結果

問題 No.1797 永遠のグリッド
ユーザー fukafukatanifukafukatani
提出日時 2022-01-01 16:25:14
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,562 bytes
コンパイル時間 1,059 ms
コンパイル使用メモリ 164,660 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-18 14:10:10
合計ジャッジ時間 1,520 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 0 ms
6,948 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1 ms
6,944 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
6,940 KB
testcase_28 AC 1 ms
6,940 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::<i128>();
    let (h, w, k) = (v[0], v[1], v[2]);
    if k == 1 {
        println!("1");
        return;
    }
    if k == 2 {
        let total = 2i128.pow((h * w) as u32) - 2;
        let raw_same = 2i128.pow(h as u32) - 2;
        let col_same = 2i128.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 = 3i128.pow((h * w) as u32) - 3 * 2i128.pow((h * w) as u32) + 3;
    let raw_same = 3i128.pow(h as u32) - 3 * 2i128.pow(h as u32) + 3;
    let col_same = 3i128.pow(w as u32) - 3 * 2i128.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