結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー tonyu0tonyu0
提出日時 2020-08-09 20:43:11
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 1,097 bytes
コンパイル時間 1,069 ms
コンパイル使用メモリ 104,624 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 15:18:55
合計ジャッジ時間 3,605 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,948 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 40 ms
6,940 KB
testcase_23 AC 40 ms
6,940 KB
testcase_24 AC 38 ms
6,944 KB
testcase_25 AC 39 ms
6,940 KB
testcase_26 AC 44 ms
6,940 KB
testcase_27 AC 45 ms
6,940 KB
testcase_28 AC 46 ms
6,944 KB
testcase_29 AC 38 ms
6,940 KB
testcase_30 AC 42 ms
6,940 KB
testcase_31 AC 40 ms
6,940 KB
testcase_32 AC 39 ms
6,944 KB
testcase_33 AC 42 ms
6,940 KB
testcase_34 AC 44 ms
6,944 KB
testcase_35 AC 44 ms
6,940 KB
testcase_36 AC 45 ms
6,940 KB
testcase_37 AC 46 ms
6,944 KB
testcase_38 AC 39 ms
6,940 KB
testcase_39 AC 39 ms
6,948 KB
testcase_40 AC 41 ms
6,940 KB
testcase_41 AC 45 ms
6,940 KB
testcase_42 AC 36 ms
6,944 KB
testcase_43 AC 34 ms
6,944 KB
testcase_44 AC 50 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

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