結果

問題 No.3235 巡回減算
ユーザー The Forsaking
提出日時 2025-08-16 12:55:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 48 ms / 10,000 ms
コード長 1,043 bytes
コンパイル時間 1,606 ms
コンパイル使用メモリ 195,372 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-16 12:55:11
合計ジャッジ時間 3,002 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
const int N = 2000086, MOD =  998244353, INF = 0x3f3f3f3f;
ll res;
int n, m, cnt, w[N];

int a[9][9], c[9];

void dfs(int idx) {
    if (idx == 9) {
        for (int i = 1; i < n + 1; i++)
            if (a[1][i] != c[i])
                return;
        puts("Yes");
        exit(0);
    }
    for (int i = 1; i <= n; i++) {
        int t = 0, ne = i;
        while (t++ != 8) {
            c[t] += a[idx][ne];
            ne = ne == 8 ? 1 : ne + 1;
        }
        for (int j = 1; j < n + 1; j++)
            if (a[1][j] < c[j])
                goto NE;
        dfs(idx + 1);
        NE:;
        t = 0, ne = i;
        while (t++ != 8) {
            c[t] -= a[idx][ne];
            ne = ne == 8 ? 1 : ne + 1;
        }
    }
}

int main() {
    n = 8;
    for (int i = 1; i < n + 1; i++) {
        string s;
        cin >> s;
        for (int j = 1; j < n + 1; j++) a[i][j] = s[j - 1] - '0';
    }
    dfs(2);
    puts("No");
    return 0;
}
0