結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー Strorkis
提出日時 2020-08-07 23:15:22
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 1,837 bytes
コンパイル時間 14,133 ms
コンパイル使用メモリ 395,016 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-25 00:01:41
合計ジャッジ時間 15,941 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 2 WA * 41
権限があれば一括ダウンロードができます

ソースコード

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