結果
| 問題 |
No.1150 シュークリームゲーム(Easy)
|
| コンテスト | |
| ユーザー |
Strorkis
|
| 提出日時 | 2020-08-07 23:52:21 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 2,000 ms |
| コード長 | 1,473 bytes |
| コンパイル時間 | 15,583 ms |
| コンパイル使用メモリ | 391,752 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-25 01:25:53 |
| 合計ジャッジ時間 | 13,269 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 43 |
ソースコード
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<i64> = {
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 ans: i64 = a[s] - a[t];
let l = (n + s - t) % n - 1;
{
let (mut x, mut y) = (s, t);
for _ in 0..(l / 2) {
x = (n + x - 1) % n;
y = (y + 1) % n;
ans += a[x] - a[y];
}
}
let r = n - 2 - l;
{
let (mut x, mut y) = (s, t);
for _ in 0..(r / 2) {
x = (x + 1) % n;
y = (n + y - 1) % n;
ans += a[x] - a[y];
}
}
if l % 2 == 1 && r % 2 == 1 {
ans += (a[(n + s - (l + 1) / 2) % n] - a[(s + (r + 1) / 2) % n]).abs();
} else if l % 2 == 1 {
ans += a[(n + s - (l + 1) / 2) % n];
} else if r % 2 == 1 {
ans += a[(s + (r + 1) / 2) % n];
}
println!("{}", ans);
}
Strorkis