QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#19446#1811. How to Move the BeansYaoBIG#RE 2ms3676kbC++203.4kb2022-01-31 04:24:172022-05-06 05:22:46

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-06 05:22:46]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:3676kb
  • [2022-01-31 04:24:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int H = 1000;
const int W = 1000;
const int N = 2*W;
string arr[H];

using bwp = pair<bitset<W>, bitset<W>>;

void sl(bitset<W>& bs, int w) {
	int x = bs[0];
	bs >>= 1;
	bs[w - 1] = x;
}

void sr(bitset<W>& bs, int w) {
	int x = bs[w - 1];
	bs <<= 1;
	bs[0] = x;
}

bwp pwMex(const bwp& b0, const bwp& b1) {
	bitset<W> have_0 = b0.first | b1.first;
	bitset<W> have_1 = b0.second | b1.second;
	return {~have_0, have_0 & ~have_1};
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int h, w;
	cin >> h >> w;
	for (int y = 0; y < h; ++y) cin >> arr[y];

	bwp pre;
	bitset<W> is_3;
	is_3.set();
	int grundy = 0;
	
	for (int y = h-1; y >= 0; --y) {
		int wall_x = -1;
		for (int x = 0; x < w; ++x) {
			if (arr[y][x] == '#') wall_x = x;
		}
		if (wall_x != -1) {
			vector<int> dp_le(w, 3);
			for (int x = wall_x + 1; x != wall_x; x = (x + 1) % w) {
				if (arr[y][x] == '#') continue;
				int pv = (x == 0 ? dp_le[w-1] : dp_le[x-1]);
				int v2 = (is_3[x] ? 3 : (1 - pre.first[x]) + (1 - (pre.first[x] || pre.second[x])));
				
				int v = 0;
				while(v == pv || v == v2) ++v;
				dp_le[x] = v;
			}

			vector<int> dp_ri(w, 3);
			for (int x = (wall_x + w-1) % w; x != wall_x; x = (x + w-1) % w) {
				if (arr[y][x] == '#') continue;
				int pv = (x == w-1 ? dp_ri[0] : dp_ri[x+1]);
				int v2 = (is_3[x] ? 3 : (1 - pre.first[x]) + (1 - (pre.first[x] || pre.second[x])));
				
				int v = 0;
				while(v == pv || v == v2) ++v;
				dp_ri[x] = v;
			}

			for (int x = 0; x < w; ++x) {
				if (arr[y][x] == '#') {
					pre.first[x] = 0;
					pre.second[x] = 0;
					is_3[x] = 1;
				} else {
					int v0 = dp_le[(x + w-1) % w];
					int v1 = dp_ri[(x + 1)   % w];
					int v2 = (is_3[x] ? 3 : (1 - pre.first[x]) + (1 - (pre.first[x] || pre.second[x])));
					
					int v = 0;
					while(v == v0 || v == v1 || v == v2) ++v;

					if (arr[y][x] == 'B') grundy ^= v;
					is_3[x] = (v == 3);
					pre.first[x] = (v == 0);
					pre.second[x] = (v == 1);
				
					// cerr << y << ' ' << x << ": " << v0 << ' ' << v1 << ' ' << v2 << " -> " << v << '\n';
				}
			}
		} else {
			bwp le;
			for (int i = 0; i < w - 1; ++i) {
				le = pwMex(le, pre);
				sl(le.first, w);
				sl(le.second, w);

				/*
				cerr << "le after " << i << ": ";
				for (int x = 0; x < w; ++x) cerr << le.first[x] << le.second[x] << ' ';
				cerr << '\n';
				*/
			}

			bwp ri;
			for (int i = 0; i < w - 1; ++i) {
				ri = pwMex(ri, pre);
				sr(ri.first, w);
				sr(ri.second, w);
				
				/*
				cerr << "ri after " << i << ": ";
				for (int x = 0; x < w; ++x) cerr << ri.first[x] << ri.second[x] << ' ';
				cerr << '\n';
				*/
			}

			for (int x = 0; x < w; ++x) {
				int v0 = (1 - le.first[x]) + (1 - (le.first[x] || le.second[x]));
				int v1 = (1 - ri.first[x]) + (1 - (ri.first[x] || ri.second[x]));
				int v2 = (is_3[x] ? 3 : (1 - pre.first[x]) + (1 - (pre.first[x] || pre.second[x])));
				int v = 0;
				while(v == v0 || v == v1 || v == v2) ++v;

				if (arr[y][x] == 'B') grundy ^= v;
				is_3[x] = (v == 3);
				pre.first[x] = (v == 0);
				pre.second[x] = (v == 1);

				// cerr << y << ' ' << x << ": " << v0 << ' ' << v1 << ' ' << v2 << " -> " << v << '\n';
			}
		}
	}

	cout << ((grundy == 0) ? "Bob" : "Alice") << '\n';
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3676kb

input:

2 3
B.#
#..

output:

Alice

result:

ok "Alice"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3536kb

input:

1 1
B

output:

Bob

result:

ok "Bob"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3560kb

input:

1 3
B#.

output:

Alice

result:

ok "Alice"

Test #4:

score: -100
Dangerous Syscalls

input:

5 18
#.#..#.#..###..###
##...#.#..#.#..#..
#....#.#..###..#..
##...#.#..#....#..
#.#..###..#....###

output:


result: