結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー どららどらら
提出日時 2020-08-07 22:53:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 2,200 bytes
コンパイル時間 2,068 ms
コンパイル使用メモリ 171,624 KB
実行使用メモリ 5,616 KB
最終ジャッジ日時 2023-10-25 03:48:45
合計ジャッジ時間 4,323 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
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 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 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 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 38 ms
5,352 KB
testcase_23 AC 39 ms
5,352 KB
testcase_24 AC 35 ms
5,352 KB
testcase_25 AC 38 ms
5,352 KB
testcase_26 AC 41 ms
5,616 KB
testcase_27 AC 42 ms
5,616 KB
testcase_28 AC 44 ms
5,616 KB
testcase_29 AC 36 ms
5,352 KB
testcase_30 AC 39 ms
5,616 KB
testcase_31 AC 38 ms
5,352 KB
testcase_32 AC 38 ms
5,352 KB
testcase_33 AC 39 ms
5,616 KB
testcase_34 AC 42 ms
5,616 KB
testcase_35 AC 42 ms
5,616 KB
testcase_36 AC 43 ms
5,616 KB
testcase_37 AC 43 ms
5,616 KB
testcase_38 AC 37 ms
5,352 KB
testcase_39 AC 37 ms
5,352 KB
testcase_40 AC 39 ms
5,616 KB
testcase_41 AC 42 ms
5,616 KB
testcase_42 AC 34 ms
5,616 KB
testcase_43 AC 33 ms
5,616 KB
testcase_44 AC 47 ms
5,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  int s, t;
  cin >> s >> t;
  s--; t--;
  vector<ll> tmp;
  rep(i,N){
    ll a;
    cin >> a;
    tmp.push_back(a);
  }
  vector<ll> v;
  rep(i,N){
    v.push_back(tmp[(s+i)%N]);
  }
  t = (t+N-s)%N;
  s = 0;
  
  ll X = v[s], Y = v[t];
  int rhs = t-1-s;
  int lhs = N-2-rhs;
  
  if(lhs%2==0 && rhs%2==0){
    {
      int p = s, q = t;
      while(true){
        p++; q--;
        if(p==(q+1)%N) break;
        X += v[p];
        Y += v[q];
      }
    }
    {
      int p = s, q = t;
      while(true){
        p=(p-1+N)%N;
        q=(q+1)%N;
        if(q==(p+1)%N) break;
        X += v[p];
        Y += v[q];
      }
    }
  }
  if(lhs%2==0 && rhs%2==1){
    {
      int p = s, q = t;
      while(true){
        p++; q--;
        X += v[p];
        if(p==q) break;
        Y += v[q];
      }
    }
    {
      int p = s, q = t;
      while(true){
        p=(p-1+N)%N;
        q=(q+1)%N;
        if(q==(p+1)%N) break;
        X += v[p];
        Y += v[q];
      }
    }
  }
  if(lhs%2==1 && rhs%2==0){
    {
      int p = s, q = t;
      while(true){
        p++; q--;
        if(p==(q+1)%N) break;
        X += v[p];
        Y += v[q];
      }
    }
    {
      int p = s, q = t;
      while(true){
        p=(p-1+N)%N;
        q=(q+1)%N;
        X += v[p];
        if(q==p) break;
        Y += v[q];
      }
    }
  }
  if(lhs%2==1 && rhs%2==1){
    int pp, qq;
    {
      int p = s, q = t;
      while(true){
        p++; q--;
        if(p==q) break;
        X += v[p];
        Y += v[q];
      }
      pp = p;
    }
    {
      int p = s, q = t;
      while(true){
        p=(p-1+N)%N;
        q=(q+1)%N;
        if(p==q) break;
        X += v[p];
        Y += v[q];
      }
      qq = p;
    }

    if(v[pp] > v[qq]){
      X += v[pp];
      Y += v[qq];
    }else{
      X += v[qq];
      Y += v[pp];
    }
  }

  cout << X - Y << endl;
  
  return 0;
}
0