結果

問題 No.2255 Determinant Sum
ユーザー koba-e964koba-e964
提出日時 2023-03-25 01:26:11
言語 Rust
(1.77.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 2,529 bytes
コンパイル時間 4,670 ms
コンパイル使用メモリ 171,760 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 21:52:27
合計ジャッジ時間 3,927 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 39 ms
4,348 KB
testcase_07 AC 16 ms
4,348 KB
testcase_08 AC 15 ms
4,348 KB
testcase_09 AC 16 ms
4,348 KB
testcase_10 AC 29 ms
4,348 KB
testcase_11 AC 9 ms
4,348 KB
testcase_12 AC 11 ms
4,348 KB
testcase_13 AC 8 ms
4,348 KB
testcase_14 AC 20 ms
4,348 KB
testcase_15 AC 13 ms
4,348 KB
testcase_16 AC 16 ms
4,348 KB
testcase_17 AC 13 ms
4,348 KB
testcase_18 AC 9 ms
4,348 KB
testcase_19 AC 10 ms
4,348 KB
testcase_20 AC 12 ms
4,348 KB
testcase_21 AC 10 ms
4,348 KB
testcase_22 AC 11 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;

#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}

fn get_word() -> String {
    let stdin = std::io::stdin();
    let mut stdin=stdin.lock();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

fn solve() {
    let t: usize = get();
    for _ in 0..t {
        let n: usize = get();
        let p: i32 = get();
        let mut a = vec![vec![0; n]; n];
        for i in 0..n {
            for j in 0..n {
                a[i][j] = get();
            }
        }
        if p != 2 {
            println!("0");
            continue;
        }
        let mut row = vec![0; n];
        let mut col = vec![0; n];
        for i in 0..n {
            for j in 0..n {
                if a[i][j] == -1 {
                    row[i] += 1;
                    col[j] += 1;
                }
            }
        }
        if row.iter().any(|&v| v >= 2) || col.iter().any(|&v| v >= 2) {
            println!("0");
            continue;
        }
        let mut sub = vec![];
        for i in 0..n {
            if row[i] >= 1 { continue; }
            let mut tmp = 0i64;
            for j in 0..n {
                if col[j] == 0 {
                    if a[i][j] == 1 {
                        tmp |= 1 << j;
                    }
                }
            }
            sub.push(tmp);
        }
        let mut basis = vec![];
        for &(mut s) in &sub {
            for &b in &basis {
                s = min(s, s ^ b);
            }
            if s != 0 {
                basis.push(s);
            }
        }
        println!("{}", if basis.len() == sub.len() { 1 } else { 0 });
    }
}
0