Loading

【题解】CF1733E - Conveyor

因为每秒只放一个球,所以对于每一个 \(x+y = a\) 的对角线最多只有一个球且任意两个球不会相遇,所以我们只用知道第 \(t-x-y\) 秒放的球的移动路径即可。等价于需要求出前 \(t-x-y\) 个球对地图的影响。

事实上我们只用知道每个位置被经过了多少次,经过次数的奇偶性就是地图的状态。我们记 \(f_{i,j}\) 表示格子 \((i,j)\) 被经过的次数,那么有一半的球去了右边,另一半去了下面。可以简单 \(n^2\) 递推得到答案。时间复杂度 \(\mathcal{O}(120^2q)\)

#define N 128
int x, y, n = 119; LL t, f[N][N];
void solve(){
	memset(f, 0, sizeof(f));
	read(t, x, y);
	if(!x && !y){puts("Yes"); return;}
	if(x + y > t){puts("No"); return;}
	t -= x + y;
	f[0][0] = t;
	rep(i, 0, n)rep(j, 0, n){
		if(i < n)f[i + 1][j] += f[i][j] / 2;
		if(j < n)f[i][j + 1] += (f[i][j] + 1) / 2;
	}
	int s = 0, t = 0;
	while(s <= n && t <= n){
		if(f[s][t] & 1)s++;else t++;
		if(s == x && t == y){puts("Yes"); return;}
	}
	puts("No");
}
int main() {int T; read(T); while(T--)solve();}
posted @ 2022-09-20 08:37  7KByte  阅读(100)  评论(0编辑  收藏  举报