結果

問題 No.1687 What the Heck?
コンテスト
ユーザー phspls
提出日時 2022-10-18 14:14:28
言語 Rust
(1.94.0 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
WA  
実行時間 -
コード長 805 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 10,468 ms
コンパイル使用メモリ 202,232 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-03-18 03:39:37
合計ジャッジ時間 7,712 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 8 WA * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
 --> src/main.rs:5:9
  |
5 |     let n: usize = n.trim().parse().unwrap();
  |         ^ help: if this is intentional, prefix it with an underscore: `_n`
  |
  = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default

ソースコード

diff #
raw source code

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 mut p: Vec<usize> = p.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let mut result = 0usize;
    let mut summary = p.iter().sum::<usize>();
    while p.len() > 0 && *p.last().unwrap() == p.len() {
        if summary > 2*p.len() {
            result = summary - 2*p.len();
        }
        summary -= p.len();
        p.pop();
    }
    let n = p.len();
    if n > 0 {
        let idx = (0..n).filter(|&i| p[i] == n).nth(0).unwrap() + 1;
        if summary > 2*idx {
            result = result.max(summary - 2*idx);
        }
    }
    println!("{}", result);
}
0