結果
| 問題 | No.3602 Queen XOR Score |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-07-31 03:03:37 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| + 788µs | |
| コード長 | 2,273 bytes |
| 記録 | |
| コンパイル時間 | 4,633 ms |
| コンパイル使用メモリ | 387,564 KB |
| 実行使用メモリ | 5,888 KB |
| 最終ジャッジ日時 | 2026-07-31 03:03:52 |
| 合計ジャッジ時間 | 6,560 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 |
ソースコード
#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>;
mt19937 mt(random_device{}());
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];
// rep(i, 0, h) rep(j, 0, w) a[i][j] = mt();
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;
// nw = mt();
bst nb;
if (nw == 0) {
if (!f0) {
cout << "-1\n";
continue;
}
nb = eq0;
} else {
for (auto& [x, b] : base) {
if (chmin(nw, nw ^ x)) nb ^= b;
}
if (nw != 0) {
cout << "-1\n";
continue;
}
}
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) {
if (y > 0) {
vp.push_back({i, 0});
vp.push_back({i, j});
vp.push_back({i, 0});
} else assert(0);
} else 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});
}
}
}
assert((int)vp.size() <= 2 * h * w);
cout << vp.size() - 1 << '\n';
for (auto [x, y] : vp) {
if (rflg) swap(x, y);
cout << x + 1 << ' ' << y + 1 << '\n';
}
rep(i, 0, vp.size() - 1) {
int d = vp[i].first == vp[i + 1].first;
int b = vp[i].second == vp[i + 1].second;
if (!(b ^ d)) cout << endl;
assert(b ^ d);
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int t = 1;
// cin >> t;
while (t--) solve();
}