結果

問題 No.3235 巡回減算
ユーザー GOTKAKO
提出日時 2025-08-15 21:37:33
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 170 ms / 10,000 ms
コード長 963 bytes
コンパイル時間 1,962 ms
コンパイル使用メモリ 205,136 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-08-15 21:37:44
合計ジャッジ時間 6,275 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

    int n = 8;
    vector<vector<int>> A(n);
    for(auto &a : A){
        a.resize(n);
        string s; cin >> s;
        for(int i=0; i<n; i++) a.at(i) = s.at(i)-'0';
    }

    vector<int> V = A.at(0);
    bool ok = false;
    auto dfs = [&](auto dfs,int pos) -> void {
        if(pos == n){
            bool zero = true;
            for(auto v : V) if(v){zero = false; break;}
            if(zero) ok = true;
            return;
        }
        vector<int> memo = V;
        for(int i=0; i<8; i++){
            for(int k=0; k<8; k++) V.at(k) -= A.at(pos).at(k);
            dfs(dfs,pos+1);
            if(ok) return;
            for(int k=0; k<8; k++) V.at(k) += A.at(pos).at(k);
            rotate(V.begin(),V.begin()+1,V.end());
        }
        V = memo;
    };
    dfs(dfs,1);
    if(ok) cout << "Yes\n";
    else cout << "No\n";
}
0