結果

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

ソースコード

diff #
raw source code

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

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

    int H,W; cin >> H >> W;
    int n = 0;
    vector<pair<int,int>> P;
    vector<pair<long long,long long>> B;
    for(int i=0; i<H; i++) for(int k=0; k<W; k++){
        long long a; cin >> a;
        long long S = 1LL<<n;
        for(auto [v,s] : B) if(a > (a^v)) a = a^v,S ^= s;
        if(a == 0) continue;
        P.push_back({i,k}),B.push_back({a,S}),n++;
    }
    int Q; cin >> Q;
    while(Q--){
        long long x; cin >> x;
        if(x == 0){
            cout << "4\n";
            cout << "1 1\n";
            cout << "1 2\n";
            cout << "1 1\n";
            cout << "1 2\n";
            continue;
        }
        long long use = 0;
        for(auto [v,s] : B) if(x > (x^v)) x = x^v,use ^= s;
        
        if(x){cout << "-1\n"; continue;}

        vector<vector<int>> V(H,vector<int>(W));
        for(int i=0; i<n; i++) if(use&(1LL<<i)){
            auto [xx,yy] = P.at(i);
            V.at(xx).at(yy) = 1;
        }
        int posy = -1;
        vector<pair<int,int>> answer;
        for(int x=H-1; x>=0; x--){
            vector<int> Y;
            
            for(int y=0; y<W; y++) if(V.at(x).at(y)) Y.push_back(y);
            if(Y.size() == 0) continue;
            if(posy == -1) posy = Y.at(0);
            Y.clear();
            answer.push_back({x,posy}),V.at(x).at(posy) ^= 1;
            for(int y=0; y<W; y++) if(posy != y && V.at(x).at(y)) answer.push_back({x,y});
            if(V.at(x).at(posy)) answer.push_back({x,posy});
            else posy = answer.back().second;
        }




        cout << answer.size() << "\n";
        for(auto [x,y] : answer) cout << x+1 << " " << y+1 << "\n";
    }
}
0