NekoMio's Blog

题目描述

NIM is a game of strategy in which two players take turns removing stones from distinct piles. On each turn, a player must remove at least one stone, and may remove any number of stones provided they all come from the same pile. The player who has no stones to remove loses.

There are $n$ piles of stones, the $i$-th pile has $l_i$ stones. Alice needs to remove some of the stones from each pile (removing zero or all of the stones from a certain pile is allowed). If the $i$-th pile remains at least one stone after this operation, Alice has to pay a price of $v_i$. After Alice’s operation, Bob will create a pile of stones whose number is in $[0,m]$ and add it to the game to make sure that Alice — the player who moves first in this NIM game will lose.If he can’t ensure that Alice will lose,he will exit from the game immediately.

Now Alice has $q$ queries. Each query gives an integer $c$, and you need to calculate the minimal total price Alice needs to pay to ensure Bob’s new pile has exactly $c$ stones(making Bob exit from the game isn’t allowed,even if $c=0$). If this is impossible, print -1 instead.

输入格式

The first line contains two integers $n,m$.
Each of the following $n$ lines contains two integers $v_i,l_i$.
The next line contains an integer $q$. Each of the following $n$ lines contains an integers $c$.

输出格式

Output contains $q$ lines,containing the answer of each query in order.

数据范围与提示

Subtask # 分值（百分比） $n,q$ $l_i,m$ 特殊性质
1 15 $\leq 10$ $\leq 10$ -
2 20 $\leq 100$ $\leq 100$ -
3 20 - - 对于每个 $i$ 存在非负整数 $k$ 满足 $l_i=2^k-1$
4 20 $\leq 20000$ $\leq 20000$ $l_i,v_i$ 在范围内均匀随机（使用 std::mt19937 并对最大值取模）
5 25 - - $l_i,v_i$ 在范围内均匀随机（使用 std::mt19937 并对最大值取模）

题解

35pts

55pts

CommonAnts的证明是这样的