結果

問題 No.2446 完全列
ユーザー koba-e964koba-e964
提出日時 2023-08-25 21:52:18
言語 Rust
(1.77.0)
結果
RE  
実行時間 -
コード長 5,369 bytes
コンパイル時間 4,377 ms
コンパイル使用メモリ 168,880 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-26 01:34:27
合計ジャッジ時間 5,639 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused macro definition: `puts`
   --> Main.rs:145:18
    |
145 |     macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););}
    |                  ^^^^
    |
    = note: `#[warn(unused_macros)]` on by default

warning: unused import: `Write`
 --> Main.rs:5:15
  |
5 | use std::io::{Write, BufWriter};
  |               ^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused variable: `out`
   --> Main.rs:144:13
    |
144 |     let mut out = BufWriter::new(out.lock());
    |             ^^^ help: if this is intentional, prefix it with an underscore: `_out`
    |
    = note: `#[warn(unused_variables)]` on by default

warning: variable does not need to be mutable
   --> Main.rs:144:9
    |
144 |     let mut out = BufWriter::new(out.lock());
    |         ----^^^
    |         |
    |         help: remove this `mut`
    |
    = note: `#[warn(unused_mut)]` on by default

warning: 4 warnings emitted

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

trait Change { fn chmax(&mut self, x: Self); fn chmin(&mut self, x: Self); }
impl<T: PartialOrd> Change for T {
    fn chmax(&mut self, x: T) { if *self < x { *self = x; } }
    fn chmin(&mut self, x: T) { if *self > x { *self = x; } }
}

fn powmod(x: i64, mut e: i64, m: i64) -> i64 {
    let mut sum = 1;
    let mut cur = x % m;
    while e > 0 {
        if e % 2 != 0 {
            sum = sum * cur % m;
        }
        cur = cur * cur % m;
        e /= 2;
    }
    sum
}

// p must be prime.
// Returns (B, H) where HB = A, rows(B) = rank(A)
// A: n * m, B: r * m, H: n * r
fn find_basis_mod_p(a: &[Vec<i64>], p: i64) -> (Vec<Vec<i64>>, Vec<Vec<i64>>) {
    let n = a.len();
    let m = a[0].len();
    let aold = a.clone();
    let mut a = a.to_vec();
    let mut pos = vec![];
    let mut r = 0;
    for i in 0..n {
        for j in 0..r {
            let idx = pos[j];
            assert_eq!(a[j][idx], 1);
            let val = a[i][idx];
            for k in 0..m {
                a[i][k] -= a[j][k] * val % p;
                if a[i][k] < 0 {
                    a[i][k] += p;
                }
            }
        }
        let mut c = 0;
        while c < m && a[i][c] == 0 {
            c += 1;
        }
        if c >= m {
            continue;
        }
        a.swap(r, i);
        pos.push(c);
        let aic = a[r][c];
        let aicinv = powmod(aic, p - 2, p);
        a[r][c] = 1.into();
        for j in c + 1..m {
            a[r][j] *= aicinv;
            a[r][j] %= p;
        }
        for j in r + 1..n {
            let ajc = a[j][c];
            a[j][c] = 0;
            for k in c + 1..m {
                let val = ajc * a[r][k] % p;
                a[j][k] -= val;
                if a[j][k] < 0 {
                    a[j][k] += p;
                }
            }
        }
        r += 1;
    }
    let mut tr = vec![vec![0; r]; n];
    for i in 0..n {
        let mut cur = aold[i].clone();
        for j in 0..r {
            let idx = pos[j];
            let val = cur[idx];
            tr[i][j] = val;
            for k in idx..m {
                cur[k] -= val * a[j][k] % p;
                if cur[k] < 0 {
                    cur[k] += p;
                }
            }
        }
        assert!(cur.iter().all(|&x| x == 0), "{:?} {:?} {:?}", cur, a, aold);
    }
    (a[..r].to_vec(), tr)
}

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 out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););}
    #[allow(unused)]
    macro_rules! putvec {
        ($v:expr) => {
            for i in 0..$v.len() {
                puts!("{}{}", $v[i], if i + 1 == $v.len() {"\n"} else {" "});
            }
        }
    }
    input! {
        l: usize, m: usize, n: usize,
        a: [[i64; m]; l],
        b: [[i64; n]; m],
    }
    let mut c = vec![vec![0; l]; n];
    for i in 0..l {
        for j in 0..m {
            for k in 0..n {
                c[i][k] += a[i][j] * b[j][k];
            }
        }
    }
    if (0..l).any(|i| (0..n).any(|j| c[i][j] != 0)) {
        eprintln!("not zero");
        println!("No");
        return;
    }
    let p = 1_000_000_007;
    let mut a = a;
    let mut b = b;
    for v in &mut a {
        for v in v {
            if *v < 0 {
                *v += p;
            }
        }
    }
    for v in &mut b {
        for v in v {
            if *v < 0 {
                *v += p;
            }
        }
    }
    let (b, _) = find_basis_mod_p(&b, p);
    let rb = b.len();
    let (a, _) = find_basis_mod_p(&a, p);
    let ra = a.len();
    eprintln!("ra = {}, rb = {}", ra, rb);
    println!("{}", if m - ra == rb { "Yes" } else { "No" });
}
0