結果

問題 No.1797 永遠のグリッド
ユーザー fukafukatanifukafukatani
提出日時 2022-01-01 14:59:27
言語 Rust
(1.72.1)
結果
RE  
実行時間 -
コード長 1,608 bytes
コンパイル時間 747 ms
コンパイル使用メモリ 142,700 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-07-31 11:23:05
合計ジャッジ時間 2,163 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 WA -
testcase_11 AC 1 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (h, w, k) = (v[0], v[1], v[2]);
    if k == 1 {
        println!("1");
        return;
    }
    if h == 1 || w == 1 {
        assert!(false);
    }
    if k == 2 {
        let total = 2i64.pow((h * w) as u32) - 2;
        let raw_same = 2i64.pow(h as u32) - 2;
        let col_same = 2i64.pow(w as u32) - 2;
        let rc = raw_same + col_same;
        let ans = (total - rc) / (h * w) + raw_same / h + col_same / w;
        println!("{}", ans);
        return;
    }
    assert!(false);
    let total = 3i64.pow((h * w) as u32) - 3 * 2i64.pow((h * w) as u32) + 3;
    let raw_same = 3i64.pow(h as u32) - 3 * 2i64.pow(h as u32) + 3;
    let col_same = 3i64.pow(w as u32) - 3 * 2i64.pow(w as u32) + 3;
    let rc = raw_same + col_same;
    debug!(total, raw_same, col_same);
    let ans = (total - rc) / (h * w) + raw_same / h + col_same / w;
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
0