結果
| 問題 |
No.1150 シュークリームゲーム(Easy)
|
| コンテスト | |
| ユーザー |
tonegawa
|
| 提出日時 | 2020-08-13 02:26:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 78 ms / 2,000 ms |
| コード長 | 1,097 bytes |
| コンパイル時間 | 1,526 ms |
| コンパイル使用メモリ | 99,920 KB |
| 最終ジャッジ日時 | 2025-01-12 21:33:14 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 43 |
ソースコード
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
int main() {
int n, s, t;
cin >> n >> s >> t;
--s, --t;
vector<ll> a(n);
for (ll& x : a) cin >> x;
vector<ll> x, y;
for (int i = (s + 1) % n; i != t; i = (i + 1) % n) x.push_back(a[i]);
for (int i = (t + 1) % n; i != s; i = (i + 1) % n) y.push_back(a[i]);
reverse(y.begin(), y.end());
int xs = (int)x.size();
int ys = (int)y.size();
ll vs = a[s], vt = a[t];
if (xs % 2 == 0) {
rep(i, 0, xs / 2) vs += x[i];
rep(i, xs / 2, xs) vt += x[i];
} else {
rep(i, 0, xs / 2 + 1) vs += x[i];
rep(i, xs / 2 + 1, xs) vt += x[i];
}
if (ys % 2 == 0) {
rep(i, 0, ys / 2) vs += y[i];
rep(i, ys / 2, ys) vt += y[i];
} else {
rep(i, 0, ys / 2 + 1) vs += y[i];
rep(i, ys / 2 + 1, ys) vt += y[i];
}
if (xs & 1 && ys & 1) {
ll mn = min(x[xs / 2], y[ys / 2]);
vs -= mn;
vt += mn;
}
cout << vs - vt << endl;
return 0;
}
tonegawa