結果

問題 No.1056 2D Lamps
ユーザー QCFiumQCFium
提出日時 2020-05-15 22:20:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 680 ms / 3,000 ms
コード長 2,282 bytes
コンパイル時間 2,182 ms
コンパイル使用メモリ 183,320 KB
実行使用メモリ 6,168 KB
最終ジャッジ日時 2023-10-19 14:58:37
合計ジャッジ時間 9,670 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 567 ms
6,168 KB
testcase_04 AC 564 ms
6,168 KB
testcase_05 AC 566 ms
6,168 KB
testcase_06 AC 567 ms
6,168 KB
testcase_07 AC 680 ms
6,168 KB
testcase_08 AC 669 ms
6,168 KB
testcase_09 AC 592 ms
6,168 KB
testcase_10 AC 592 ms
6,168 KB
testcase_11 AC 576 ms
6,168 KB
testcase_12 AC 573 ms
6,168 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 8 ms
4,348 KB
testcase_15 AC 10 ms
4,348 KB
testcase_16 AC 13 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define MAX_N 200
bool solve(const std::vector<std::bitset<2 * MAX_N - 1> > &a) {
	int n = a.size();
	std::bitset<2 * MAX_N - 1> plus;
	std::bitset<2 * MAX_N - 1> minus;
	
	for (int i = 2; i < 2 * n - 1; i += 2) {
		int x = (i - 2) >> 1;
		int y = n - 2 - x;
		minus[i] = minus[i - 2] ^ a[x][y] ^ a[x + 1][y] ^ a[x][y + 1] ^ a[x + 1][y + 1];
	}
	
	for (int i = 3; i < 2 * n - 1; i += 2) {
		int x = (i - 3) >> 1;
		int y = n - 3 - x;
		minus[i] = minus[i - 2] ^ a[x][y] ^ a[x + 1][y] ^ a[x][y + 1] ^ a[x + 1][y + 1];
	}
	for (int i = n - 4; i >= 0; i--) plus[i] = plus[i + 2] ^ minus[n - i] ^ minus[n - 2 - i] ^ a[0][i] ^ a[1][i] ^ a[0][i + 1] ^ a[1][i + 1];
	for (int i = n + 1; i < 2 * n - 1; i++) plus[i] = plus[i - 2] ^ minus[i - n] ^ minus[i - n + 2] ^
		a[i - n][n - 2] ^ a[i - n + 1][n - 2] ^ a[i - n][n - 1] ^ a[i - n + 1][n - 1];
	// reverse minus
	for (int i = 0; i < n; i++) {
		bool tmp = minus[i];
		minus[i] = minus[2 * n - 2 - i];
		minus[2 * n - 2 - i] = tmp;
	}
	auto b = a;
	for (int i = 0; i < n; i++) b[i] ^= (plus >> i) ^ (minus >> (n - 1 - i));
	auto l0 = b[0] << (2 * MAX_N - 1 - n);
	auto l1 = ~b[0] << (2 * MAX_N - 1 - n);
	for (int i = 1; i < n; i++) {
		auto r0 = b[i] << (2 * MAX_N - 1 - n);
		if (r0 != l0 && r0 != l1) return false;
	}
	return true;
}

int main() {
	clock_t r0 = clock();
	int n, m;
	scanf("%d%d", &n, &m);
	
	std::vector<std::bitset<2 * MAX_N - 1> > a[m];
	for (int i = 0; i < m; i++) {
		a[i].resize(n);
		for (int j = 0; j < n; j++) {
			std::string s;
			std::cin >> s;
			for (int k = 0; k < n; k++) a[i][j][k] = s[k] == '#';
		}
	}
	clock_t r1 = clock();
	std::vector<std::string> res;
	for (int i = 0; i + 1 < m; i++) {
		std::vector<std::bitset<2 * MAX_N - 1> > tmp(n);
		std::string cur;
		for (int j = i + 1; j < m; j++) {
			for (int k = 0; k < n; k++) tmp[k] = a[i][k] ^ a[j][k];
			cur.push_back(solve(tmp) ? '1' : '0');
		}
		res.push_back(cur);
	}
	clock_t r2 = clock();
	for (auto i : res) std::cout << i << std::endl;
	clock_t r3 = clock();
	std::cerr << (double) (r1 - r0) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl;
	std::cerr << (double) (r2 - r1) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl;
	std::cerr << (double) (r3 - r2) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl;
	
	return 0;
}
0