CF1312F.Attack on Red Kingdom
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The Red Kingdom is attacked by the White King and the Black King!
The Kingdom is guarded by n castles, the i-th castle is defended by ai soldiers. To conquer the Red Kingdom, the Kings have to eliminate all the defenders.
Each day the White King launches an attack on one of the castles. Then, at night, the forces of the Black King attack a castle (possibly the same one). Then the White King attacks a castle, then the Black King, and so on. The first attack is performed by the White King.
Each attack must target a castle with at least one alive defender in it. There are three types of attacks:
- a mixed attack decreases the number of defenders in the targeted castle by x (or sets it to 0 if there are already less than x defenders);
- an infantry attack decreases the number of defenders in the targeted castle by y (or sets it to 0 if there are already less than y defenders);
- a cavalry attack decreases the number of defenders in the targeted castle by z (or sets it to 0 if there are already less than z defenders).
The mixed attack can be launched at any valid target (at any castle with at least one soldier). However, the infantry attack cannot be launched if the previous attack on the targeted castle had the same type, no matter when and by whom it was launched. The same applies to the cavalry attack. A castle that was not attacked at all can be targeted by any type of attack.
The King who launches the last attack will be glorified as the conqueror of the Red Kingdom, so both Kings want to launch the last attack (and they are wise enough to find a strategy that allows them to do it no matter what are the actions of their opponent, if such strategy exists). The White King is leading his first attack, and you are responsible for planning it. Can you calculate the number of possible options for the first attack that allow the White King to launch the last attack? Each option for the first attack is represented by the targeted castle and the type of attack, and two options are different if the targeted castles or the types of attack are different.
红王国正遭到白国王与黑国王的进攻!
王国由 n 座城堡守卫,其中第 i 座城堡有 ai 名士兵驻守。为了征服红王国,两位国王必须消灭所有守军。
每天白天,白国王对其中一座城堡发动一次攻击;随后在当夜,黑国王也对某座城堡发动一次攻击(可能与白国王攻击的是同一座城堡);接着次日白天白国王再攻一次,再当夜黑国王再攻一次,如此往复。首次攻击由白国王发起。
每次攻击必须针对一座至少还有一名存活守军的城堡。共有三种类型的攻击:
- 混合攻击:将目标城堡的守军数量减少 x(若剩余守军少于 x,则直接将其置为 0);
- 步兵攻击:将目标城堡的守军数量减少 y(若剩余守军少于 y,则直接将其置为 0);
- 骑兵攻击:将目标城堡的守军数量减少 z(若剩余守军少于 z,则直接将其置为 0)。
混合攻击可对任意一座尚有至少一名士兵的城堡发动。然而,步兵攻击不可对某座城堡发动,如果该城堡上一次遭受的攻击(无论发生在何时、由谁发动)也是步兵攻击;骑兵攻击同理:若某座城堡上一次遭受的攻击是骑兵攻击,则本次不可再对其发动骑兵攻击。一座从未遭受过任何攻击的城堡,可接受任意类型的攻击。
发动最后一击的国王将被尊为红王国的征服者,因此两位国王都希望由自己发动最后一击(且他们都足够睿智,能在存在必胜策略时,找到一种无论对手如何行动均能确保获胜的策略)。白国王将发起首次攻击,而你负责为其规划这一击。请问:有多少种不同的首次攻击方案,可确保白国王最终发动最后一击?每种首次攻击方案由被攻击的城堡和攻击类型共同确定;若两方案所选城堡不同,或攻击类型不同,则视为不同方案。
输入格式
The first line contains one integer t (1≤t≤1000) — the number of test cases.
Then, the test cases follow. Each test case is represented by two lines.
The first line contains four integers n, x, y and z (1≤n≤3⋅105, 1≤x,y,z≤5).
The second line contains n integers a1, a2, ..., an (1≤ai≤1018).
It is guaranteed that the sum of values of n over all test cases in the input does not exceed 3⋅105.
第一行包含一个整数 t(1≤t≤1000)—— 表示测试用例的数量。
接下来是各测试用例。每个测试用例由两行组成。
第一行包含四个整数 n、x、y 和 z(1≤n≤3⋅105,1≤x,y,z≤5)。
第二行包含 n 个整数 a1、a2、...、an(1≤ai≤1018)。
保证输入中所有测试用例的 n 值之和不超过 3⋅105。
输出格式
For each test case, print the answer to it: the number of possible options for the first attack of the White King (or 0, if the Black King can launch the last attack no matter how the White King acts).
对于每个测试用例,输出其答案:白方国王首次攻击的可能方案数(若无论白方国王如何行动,黑方国王均可发动最后一次攻击,则输出 0)。
输入输出样例
输入#1
3 2 1 3 4 7 6 1 1 2 3 1 1 1 2 2 3
输出#1
2 3 0
输入#2
10 6 5 4 5 2 3 2 3 1 3 1 5 2 3 10 4 4 2 3 8 10 8 5 2 2 1 4 8 5 3 5 3 5 9 2 10 4 5 5 5 2 10 4 2 2 3 1 4 1 10 3 1 5 3 9 8 7 2 5 4 5 8 8 3 5 1 4 5 5 10
输出#2
0 2 1 2 5 12 5 0 0 2
输入解题思路,AI测评打分。不知道怎么写?