結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー tonyu0tonyu0
提出日時 2020-08-09 20:43:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,097 bytes
コンパイル時間 1,420 ms
コンパイル使用メモリ 100,344 KB
最終ジャッジ日時 2025-01-12 19:31:29
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0