結果

問題 No.1687 What the Heck?
ユーザー phsplsphspls
提出日時 2022-11-15 23:54:34
言語 Rust
(1.77.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 660 bytes
コンパイル時間 1,504 ms
コンパイル使用メモリ 172,712 KB
実行使用メモリ 6,220 KB
最終ジャッジ日時 2023-10-16 22:21:26
合計ジャッジ時間 2,678 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 5 ms
4,348 KB
testcase_08 AC 6 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 4 ms
4,348 KB
testcase_12 AC 13 ms
6,220 KB
testcase_13 AC 13 ms
6,220 KB
testcase_14 AC 13 ms
6,220 KB
testcase_15 AC 13 ms
6,220 KB
testcase_16 AC 13 ms
6,196 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 12 ms
6,220 KB
testcase_19 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let mut p = String::new();
    std::io::stdin().read_line(&mut p).ok();
    let p: Vec<usize> = p.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let mut summary = p.iter().sum::<usize>();
    let mut revmap = vec![0usize; n];
    let mut result = 0usize;
    for i in 0..n { revmap[p[i]-1] = i+1; }
    for i in (0..n).rev() {
        if summary >= revmap[i] * 2 {
            result = result.max(summary - 2 * revmap[i]);
        }
        summary -= revmap[i];
    }
    println!("{}", result);
}
0