Confliction

TimeLimit:4000MS  MemoryLimit:262144KB
64-bit integer IO format:%I64d
未提交 | 登录后收藏
Problem Description
Recently, Alice and Bob are working on a resource-sharing computation model. In this model, there are two processing units, and a memory space which could be represented as unlimited linear grids $ \ldots, A_{-3}, A_{-2}, A_{-1}, A_0, A_1, A_2, A_3, \ldots$. Each processing units has a pointer to mark exactly one grid in the memory. In each clock turn, the pointer would stay at the current grid, move the pointer one grid forward, or move the pointer one grid backward. In their work, Alice and Bob would submit their codes, and their programs would start at the same time. Initially, both pointers would be located at a random grid, and move according to a set of instructions. If both pointers are at the same grid at the same time, the confliction counter would plus one and record it(If their initial grids are the same, the counter would still record it). Now it is your job to find the maximum conflictions the counter could record.
Input
The first line is the number of test cases.
For each test case, the first is an integer $N_{Alice} (N_{Alice} \leq 100000)$, donating the length of the instructions of Alice.

The next $N_{Alice}$ lines describe Alice`s instructions. Each line consists of two integer $c, t$. $c$ could be $-1, 0, 1$, donating moving forward, staying, and moving backward respectively. $t$ is a non-negative integer donating that the instruction $c$ would be executed $t$ times, in the next $t$ clock turns.

The next line is an integer $N_{Bob} (N_{Bob} \leq 100000)$, donating the length of the instructions of Bob.

The next $N_{Bob}$ lines describe Bob`s instructions. Each line consists of two integer $c, t$. $c$ could be $-1, 0, 1$, donating moving forward, staying, and moving backward respectively. $t$ is a non-negative integer donating that the instruction $c$ would be executed $t$ times, in the next $t$ clock turns.

Suppose $L_{Alice}$ equals the sum of all $t$ in Alice's program, and $L_{Bob}$ equals the sum of all $t$ in Bob's program.
It is guaranteed $L_{Alice} = L_{Bob}$ and $L_{Alice}, L_{Bob} \leq 10^{18}$.
Output
For each test case, output a line containing the maximum conflictions.
SampleInput
2
1
1 2
2
1 1
-1 1
1
0 6
4
-1 2
1 1
-1 2
1 1
SampleOutput
2
3
Submit
题目统计信息详细
总AC数0
通过人数0
尝试人数0
总提交量0
AC率0.00%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: