結果

問題 No.3235 巡回減算
ユーザー urectanc
提出日時 2025-08-15 22:25:13
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 178 ms / 10,000 ms
コード長 866 bytes
コンパイル時間 12,087 ms
コンパイル使用メモリ 401,088 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-15 22:26:10
合計ジャッジ時間 13,466 ms
ジャッジサーバーID
(参考情報)
judge5 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

use proconio::{input, marker::Bytes};

fn main() {
    let n = 8;
    input! {
        mut a: [Bytes; n],
    }
    a.iter_mut().flatten().for_each(|x| *x -= b'0');

    let ans = dfs(&a, 1, &mut a[0].clone());
    println!("{}", if ans { "Yes" } else { "No" });
}

fn dfs(a: &Vec<Vec<u8>>, i: usize, current: &mut Vec<u8>) -> bool {
    let n = a.len();
    if i == n {
        let res = current.iter().all(|&x| x == 0);
        return res;
    }

    let mut row = a[i].clone();
    let mut res = false;
    for _ in 0..n {
        let possible = (0..n).all(|j| current[j] >= row[j]);
        if possible {
            for j in 0..n {
                current[j] -= row[j];
            }
            res |= dfs(a, i + 1, current);
            for j in 0..n {
                current[j] += row[j];
            }
        }
        row.rotate_left(1);
    }
    res
}
0