結果

問題 No.77 レンガのピラミッド
ユーザー phsplsphspls
提出日時 2020-05-24 13:48:00
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 969 bytes
コンパイル時間 6,105 ms
コンパイル使用メモリ 154,496 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 15:02:52
合計ジャッジ時間 2,609 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

use std::cmp::min;

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

    let mut base: usize = 1;
    for i in 0..asum {
        if asum < i*(i+1)+i+1 {
            base = 2*(i-1) + 1;
            break;
        }
    }
    let mut pyramid: Vec<usize> = (0..base).map(|i| min(base/2+1, i+1) - if i > base/2 { i-base/2 } else { 0 }).collect();
    if base > n {
        (0..base-n).for_each(|_| a.push(0));
    } else if n > base {
        (0..n-base).for_each(|_| pyramid.push(0));
    }
    let result: usize = a.iter().zip(pyramid.iter())
        .map(|pair| if pair.0 > pair.1 { pair.0 - pair.1 } else { 0 })
        .sum()
    ;
    println!("{}", result);
}
0