結果
| 問題 |
No.77 レンガのピラミッド
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-29 11:20:13 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 969 bytes |
| コンパイル時間 | 12,425 ms |
| コンパイル使用メモリ | 391,688 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2025-01-02 13:13:03 |
| 合計ジャッジ時間 | 13,695 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 20 |
ソースコード
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<usize> = (0..n)
.map(|_| itr.next().unwrap().parse().unwrap())
.collect();
let sum = a.iter().fold(0, |acc, x| acc + x);
let mut height = 1;
while height * (height + 1) + height + 1 <= sum {
height += 1;
}
let hidx = height - 1;
a.resize(hidx * 2 + 1, 0);
let excess = sum - height * (height - 1) - height;
let mut need = 0;
if a[hidx] < height {
need = height - a[hidx];
}
for i in 0..hidx {
if i < hidx * 2 + 1 && a[i] < i + 1 {
need += i + 1 - a[i];
}
if hidx * 2 - i < hidx * 2 + 1 && a[hidx * 2 - i] < i + 1 {
need += i + 1 - a[hidx * 2 - i];
}
}
println!("{}", excess + need);
}