結果
| 問題 | No.1687 What the Heck? |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-18 14:14:28 |
| 言語 | Rust (1.92.0 + proconio + num) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 805 bytes |
| 記録 | |
| コンパイル時間 | 20,586 ms |
| コンパイル使用メモリ | 378,352 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-28 22:29:24 |
| 合計ジャッジ時間 | 19,539 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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)]` on by default
ソースコード
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);
}