結果
問題 |
No.1150 シュークリームゲーム(Easy)
|
ユーザー |
|
提出日時 | 2024-09-12 14:34:46 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 1,382 bytes |
コンパイル時間 | 12,912 ms |
コンパイル使用メモリ | 402,604 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-12 14:35:02 |
合計ジャッジ時間 | 14,715 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 43 |
ソースコード
use proconio::{input, marker::Usize1}; fn main() { input! { n:usize, s:Usize1, t:Usize1, a:[usize;n], } let ans = if n % 2 != 0 { let mut point = [0, 0]; for i in 0..n { match f(s, t, i, n) { 0 | 2 => point[0] += a[i], _ => point[1] += a[i], } // println!("{:?}",point); } point[0] as i64 - point[1] as i64 } else { let mut point = [0, 0]; let mut tmp = vec![]; for i in 0..n { match f(s, t, i, n) { 0 => point[0] += a[i], 1 => point[1] += a[i], _ => tmp.push(a[i]), } // println!("{:?}",point); } let (add_s, add_t) = if tmp.is_empty() { (0, 0) } else { (tmp[0].max(tmp[1]), tmp[0].min(tmp[1])) }; (point[0] + add_s) as i64 - (point[1] + add_t) as i64 }; println!("{}", ans); } fn f(s: usize, t: usize, p: usize, n: usize) -> usize { let d_s = if s < p { (p - s).min(s + n - p) } else { (s - p).min(p + n - s) }; let d_t = if t < p { (p - t).min(t + n - p) } else { (t - p).min(p + n - t) }; if d_s < d_t { 0 } else if d_t < d_s { 1 } else { 2 } }