結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー IKyoproIKyopro
提出日時 2020-08-07 21:35:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,272 bytes
コンパイル時間 3,079 ms
コンパイル使用メモリ 206,160 KB
実行使用メモリ 5,356 KB
最終ジャッジ日時 2023-10-25 00:24:02
合計ジャッジ時間 4,434 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 2 ms
4,372 KB
testcase_11 AC 2 ms
4,372 KB
testcase_12 AC 2 ms
4,372 KB
testcase_13 AC 2 ms
4,372 KB
testcase_14 AC 2 ms
4,372 KB
testcase_15 AC 2 ms
4,372 KB
testcase_16 AC 2 ms
4,372 KB
testcase_17 AC 2 ms
4,372 KB
testcase_18 AC 2 ms
4,372 KB
testcase_19 AC 2 ms
4,372 KB
testcase_20 AC 2 ms
4,372 KB
testcase_21 AC 2 ms
4,372 KB
testcase_22 AC 14 ms
5,076 KB
testcase_23 AC 14 ms
4,996 KB
testcase_24 AC 13 ms
4,944 KB
testcase_25 AC 13 ms
4,976 KB
testcase_26 AC 15 ms
5,232 KB
testcase_27 AC 15 ms
5,324 KB
testcase_28 AC 16 ms
5,092 KB
testcase_29 AC 13 ms
4,820 KB
testcase_30 AC 14 ms
5,020 KB
testcase_31 AC 14 ms
5,260 KB
testcase_32 AC 14 ms
5,016 KB
testcase_33 AC 14 ms
5,020 KB
testcase_34 AC 15 ms
5,052 KB
testcase_35 AC 15 ms
5,180 KB
testcase_36 AC 15 ms
5,168 KB
testcase_37 AC 16 ms
5,356 KB
testcase_38 AC 13 ms
4,968 KB
testcase_39 AC 14 ms
5,084 KB
testcase_40 AC 14 ms
5,016 KB
testcase_41 AC 15 ms
5,068 KB
testcase_42 AC 13 ms
5,100 KB
testcase_43 AC 13 ms
5,100 KB
testcase_44 AC 17 ms
5,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,S,T;
    cin >> N >> S >> T;
    S--; T--;
    vec<ll> A(N);
    for(auto& x:A) cin >> x;
    vec<ll> X,Y;
    for(int i=(S+1)%N;;(i+=1)%=N){
        if(i==T) break;
        X.push_back(A[i]);
    }
    for(int i=(S-1+N)%N;;(i+=-1+N)%=N){
        if(i==T) break;
        Y.push_back(A[i]);
    }
    int n = X.size(),m = Y.size();
    if(n%2 && m%2){
        ll s = A[S]-A[T];
        vec<ll> c(2);
        for(int i=0;i<n;i++){
            if(i<n/2) s += X[i];
            else if(i==n/2) c[0] = X[i];
            else s -= X[i];
        }
        for(int i=0;i<m;i++){
            if(i<m/2) s += Y[i];
            else if(i==m/2) c[1] = Y[i];
            else s -= Y[i];
        }
        if(c[0]<c[1]) swap(c[0],c[1]);
        cout << s+c[0]-c[1] << "\n";
    }else{
        ll s = A[S]-A[T];
        for(int i=0;i<n;i++){
            if(i<=(n-1)/2) s += X[i];
            else s -= X[i];
        }
        for(int i=0;i<m;i++){
            if(i<=(m-1)/2) s += Y[i];
            else s -= Y[i];
        }
        cout << s << "\n";
    }
}
0