結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー StrorkisStrorkis
提出日時 2020-08-07 23:15:22
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,837 bytes
コンパイル時間 839 ms
コンパイル使用メモリ 170,604 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 04:36:49
合計ジャッジ時間 2,445 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 0 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 8 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp;

fn main() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    let (s, t): (usize, usize) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        (
            iter.next().unwrap().parse::<usize>().unwrap() - 1,
            iter.next().unwrap().parse::<usize>().unwrap() - 1,
        )
    };

    let a: Vec<usize> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect()
    };

    let (mut l0, mut l1) = (s, t);
    let (mut r0, mut r1) = (s, t);
    let (mut c0, mut c1) = (a[s], a[t]);
    for i in 0..(n - 2) {
        if i % 2 == 0 {
            let d0 = cmp::max(l0, r1) - cmp::min(l0, r1);
            let x0 = (r1 + (d0 + 1) / 2) % n;
            let d1 = cmp::max(l1, r0) - cmp::min(l1, r0);
            let x1 = (l1 + (d1 + 1) / 2) % n;
            if d1 == 1 || d0 != 1 && a[x0] > a[x1] {
                l0 = (l0 + n - 1) % n;
                c0 += a[x0];
            } else {
                r0 = (r0 + 1) % n;
                c0 += a[x1];
            }
        } else {
            let d0 = cmp::max(l0, r1) - cmp::min(l0, r1);
            let x0 = (l0 + (d0 + 1) / 2) % n;
            let d1 = cmp::max(l1, r0) - cmp::min(l1, r0);
            let x1 = (r0 + (d1 + 1) / 2) % n;
            if d1 == 1 || d0 != 1 && a[x0] > a[x1] {
                r1 = (r1 + 1) % n;
                c1 += a[x0];
            } else {
                l1 = (l1 + n - 1) % n;
                c1 += a[x1];
            }
        }
    }

    println!("{}", c0 as isize - c1 as isize);
}
0