結果

問題 No.2835 Take and Flip
ユーザー naut3naut3
提出日時 2024-08-09 21:25:40
言語 Rust
(1.77.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 603 bytes
コンパイル時間 13,444 ms
コンパイル使用メモリ 382,020 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2024-08-09 21:26:03
合計ジャッジ時間 15,822 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 51 ms
12,800 KB
testcase_04 AC 51 ms
12,928 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 59 ms
10,368 KB
testcase_07 AC 61 ms
10,496 KB
testcase_08 AC 55 ms
9,728 KB
testcase_09 AC 65 ms
11,264 KB
testcase_10 AC 65 ms
11,136 KB
testcase_11 AC 69 ms
11,136 KB
testcase_12 AC 65 ms
11,136 KB
testcase_13 AC 67 ms
11,008 KB
testcase_14 AC 25 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 40 ms
7,808 KB
testcase_17 AC 4 ms
6,944 KB
testcase_18 AC 50 ms
9,216 KB
testcase_19 AC 63 ms
10,624 KB
testcase_20 AC 21 ms
6,940 KB
testcase_21 AC 58 ms
10,112 KB
testcase_22 AC 41 ms
7,936 KB
testcase_23 AC 17 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case)]
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        N: usize,
        A: [isize; N],
    }

    let mut ans = 0;
    let mut S = {
        let mut s = std::collections::BTreeSet::new();

        for i in 0..N {
            s.insert((A[i], i));
        }

        s
    };

    for i in 0..N {
        if i % 2 == 0 {
            let m = S.pop_last().unwrap().0;
            ans += m;
        } else {
            let m = S.pop_last().unwrap().0;
            ans += -(-m);
        }
    }

    println!("{}", ans);
}
0