結果

問題 No.1974 2x2 Flipper
ユーザー phsplsphspls
提出日時 2022-09-27 11:56:53
言語 Rust
(1.77.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,475 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 152,328 KB
実行使用メモリ 9,896 KB
最終ジャッジ日時 2023-08-24 03:44:33
合計ジャッジ時間 5,928 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 7 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 18 ms
4,380 KB
testcase_06 AC 6 ms
4,380 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 7 ms
4,380 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 7 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 8 ms
4,376 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 7 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 9 ms
4,376 KB
testcase_22 AC 9 ms
4,376 KB
testcase_23 AC 9 ms
4,376 KB
testcase_24 AC 80 ms
9,896 KB
testcase_25 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `i`
  --> Main.rs:25:13
   |
25 |         for i in 0..h.max(w) {
   |             ^ help: if this is intentional, prefix it with an underscore: `_i`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

fn main() {
    let mut hw = String::new();
    std::io::stdin().read_line(&mut hw).ok();
    let hw: Vec<usize> = hw.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let h = hw[0];
    let w = hw[1];

    if h % 2 == 0 && w % 2 == 0 {
        println!("{}", h*w);
        for _ in 0..h { println!("{}", vec!["1"; w].join(" ")); }
    } else if h % 2 == 0 {
        println!("{}", h * (w-1));
        for _ in 0..h {
            println!("{} 0", vec!["1"; w-1].join(" "));
        }
    } else if w % 2 == 0 {
        println!("{}", (h-1)*w);
        for _ in 0..h-1 { println!("{}", vec!["1"; w].join(" ")); }
        println!("{}", vec!["0"; w].join(" "));
    } else {
        println!("{}", (h.min(w) - 1) * h.max(w));
        let mut ret = vec![vec![1usize; w]; h];
        for i in 0..h.min(w) { ret[i][i] = 0; }
        for i in 0..h.max(w) {
            let mut idx = 0usize;
            if h > w {
                for j in (w..h).step_by(2) {
                    ret[j][idx] = 0;
                    ret[j+1][idx] = 0;
                    idx = (idx + 1) % w;
                }
            } else {
                for j in (h..w).step_by(2) {
                    ret[idx][j] = 0;
                    ret[idx][j+1] = 0;
                    idx = (idx + 1) % h;
                }
            }
        }
        for i in 0..h {
            println!("{}", ret[i].iter().map(|v| v.to_string()).collect::<Vec<String>>().join(" "));
        }
    }
}
0