結果

問題 No.1028 闇討ち
ユーザー tonyu0tonyu0
提出日時 2020-04-17 22:48:54
言語 Rust
(1.77.0)
結果
AC  
実行時間 1,188 ms / 2,000 ms
コード長 823 bytes
コンパイル時間 672 ms
コンパイル使用メモリ 167,612 KB
実行使用メモリ 23,680 KB
最終ジャッジ日時 2024-04-14 15:04:22
合計ジャッジ時間 11,876 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 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,944 KB
testcase_09 AC 12 ms
6,944 KB
testcase_10 AC 19 ms
6,944 KB
testcase_11 AC 134 ms
7,040 KB
testcase_12 AC 1,079 ms
22,784 KB
testcase_13 AC 1,069 ms
22,656 KB
testcase_14 AC 444 ms
16,384 KB
testcase_15 AC 88 ms
6,940 KB
testcase_16 AC 1,179 ms
23,552 KB
testcase_17 AC 1,176 ms
23,424 KB
testcase_18 AC 1,183 ms
23,680 KB
testcase_19 AC 1,183 ms
23,424 KB
testcase_20 AC 1,188 ms
23,680 KB
testcase_21 AC 1,184 ms
23,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();

    let mut a = vec![Vec::new(); 1010];
    for i in 0..n {
        for j in 0..n {
            let b = itr.next().unwrap().parse::<usize>().unwrap() - 1;
            a[b].push((i, j));
        }
    }

    let mut ans = 0;
    for i in 0..n {
        let mut tmp = 1 << 30;
        for pos in 0..n {
            let mut sum = 0;
            for &(y, x) in a[i].iter() {
                let z = (y as isize - pos as isize).abs() as usize;
                sum += max(z, x);
            }
            tmp = min(tmp, sum);
        }
        ans += tmp;
    }
    println!("{}", ans);
}
0