結果

問題 No.3602 Queen XOR Score
コンテスト
ユーザー cho435
提出日時 2026-07-31 02:37:56
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,824 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,665 ms
コンパイル使用メモリ 385,852 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-31 02:38:04
合計ジャッジ時間 6,588 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define all(x) begin(x), end(x)

template <class T> bool chmin(T& x, T y) {
	return x > y ? (x = y, true) : false;
}
template <class T> bool chmax(T& x, T y) {
	return x < y ? (x = y, true) : false;
}

using bst = bitset<410>;

void solve() {
	int h, w;
	cin >> h >> w;
	vector a(h, vector<ll>(w, 0));
	rep(i, 0, h) rep(j, 0, w) cin >> a[i][j];
	int rflg = 0;
	if (h > w) {
		vector ra(w, vector<ll>(h));
		rep(i, 0, h) rep(j, 0, w) ra[j][i] = a[i][j];
		swap(h, w);
		swap(a, ra);
		rflg = 1;
	}
	vector<pair<ll, bst>> base;
	bst eq0;
	int f0 = 0;
	rep(i, 0, h) rep(j, 0, w) {
		bst nb;
		nb.set(i * w + j);
		ll nw = a[i][j];
		for (auto& [x, b] : base) {
			if (chmin(nw, nw ^ x)) nb ^= b;
		}
		if (nw > 0) base.push_back({nw, nb});
		else if (!f0) eq0 = nb, f0 = 1;
	}
	int q;
	cin >> q;
	while (q--) {
		ll nw;
		cin >> nw;
		bst nb;
		if (nw == 0) {
			if (!f0) {
				cout << "-1\n";
				return;
			}
			nb = eq0;
		} else {
			for (auto& [x, b] : base) {
				if (chmin(nw, nw ^ x)) nb ^= b;
			}
			if (nw != 0) {
				cout << "-1\n";
				return;
			}
		}
		vector<pair<int, int>> vp;
		rep(i, 0, h) rep(j, 0, w) if (nb[i * w + j]) {
			if (vp.empty()) vp.push_back({i, j});
			else {
				auto [x, y] = vp.back();
				if (x == i || y == j) vp.push_back({i, j});
				else {
					vp.push_back({i, y});
					vp.push_back({i, j});
					vp.push_back({i, y});
				}
			}
		}
		if (rflg)
			for (auto& [x, y] : vp) swap(x, y);
		cout << vp.size() - 1 << '\n';
		for (auto [x, y] : vp) cout << x + 1 << ' ' << y + 1 << '\n';
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	int t = 1;
	// cin >> t;
	while (t--) solve();
}
0