結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー SSRSSSRS
提出日時 2020-08-07 21:35:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,555 bytes
コンパイル時間 1,903 ms
コンパイル使用メモリ 178,264 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 00:25:14
合計ジャッジ時間 4,412 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int prev(int x, int N){
  if (x == 0){
    return N - 1;
  } else {
    return x - 1;
  }
}
int next(int x, int N){
  if (x == N - 1){
    return 0;
  } else {
    return x + 1;
  }
}
int main(){
  int N;
  cin >> N;
  int s, t;
  cin >> s >> t;
  s--;
  t--;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<bool> used(N, false);
  used[s] = true;
  used[t] = true;
  long long X = A[s];
  long long Y = A[t];
  priority_queue<pair<int, int>> pq1, pq2;
  pq1.push(make_pair(A[prev(s, N)], prev(s, N)));
  pq1.push(make_pair(A[next(s, N)], next(s, N)));
  pq2.push(make_pair(A[prev(t, N)], prev(t, N)));
  pq2.push(make_pair(A[next(t, N)], next(t, N)));
  for (int i = 0; i < N - 2; i++){
    if (i % 2 == 0){
      while (used[pq1.top().second]){
        pq1.pop();
      }
      X += pq1.top().first;
      int p = pq1.top().second;
      used[p] = true;
      pq1.pop();
      if (!used[prev(p, N)]){
        pq1.push(make_pair(A[prev(p, N)], prev(p, N)));
      }
      if (!used[next(p, N)]){
        pq1.push(make_pair(A[next(p, N)], next(p, N)));
      }
    }
    if (i % 2 == 1){
      while (used[pq2.top().second]){
        pq2.pop();
      }
      Y += pq2.top().first;
      int p = pq2.top().second;
      used[p] = true;
      pq2.pop();
      if (!used[prev(p, N)]){
        pq2.push(make_pair(A[prev(p, N)], prev(p, N)));
      }
      if (!used[next(p, N)]){
        pq2.push(make_pair(A[next(p, N)], next(p, N)));
      }
    }
  }
  cout << X - Y << endl;
}
0