結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー mtsdmtsd
提出日時 2020-08-07 21:46:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,931 bytes
コンパイル時間 1,103 ms
コンパイル使用メモリ 119,004 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 00:40:34
合計ジャッジ時間 5,202 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}

int main(){
    int n;
    cin >> n;
    int s,t;
    cin >> s >> t;
    s--;t--;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll sm = accumulate(all(a),0LL);
    int L = 0;
    int R = 0;
    int b = s;
    int c = t;
    bool f = 0;
    while(abs(b-c)>1){
        if(!f){
            f = 1;
            b++;
            if(b>=n)b-=n;
            if(b==c){
                b--;
                if(b<0)b+=n;
                break;
            }
        }else{
            f = 0;
            c--;
            if(c<0)c+=n;
        }
    }
    L = b;
    b = s;
    c = t;
    f = 0;
    while(abs(b-c)>1){
        if(!f){
            f = 1;
            b--;
            if(b<0)b+=n;
            if(b==c){
                b++;
                if(b>=n)b-=n;
                break;
            }
        }else{
            f = 0;
            c++;
            if(c>=n)c-=n;
        }
    }
    R = b;
    if(L>R){
        swap(L,R);
    }
    cerr << L << " " << R << endl;
    int m;
    if(n%2==0){
        m = n/2;
    }else{
        m = n/2+1;
    }
    ll mx = 0;
    if(s>=L){
        ll t = 0;
        int p,q;
        for(int i=0;i<m;i++){
            t += a[(L+i)%n];
        }
        mx = t;
        p = L;
        q = (L+m)%n;
        while((q+m-1)%m!=R){
            // cerr << p << " " <<  t << endl;
            t -= a[p];
            t += a[q];
            p++;
            q++;
            p%=n;
            q%=n;
            chmax(mx,t);
        }
    }else{
        ll t = 0;
        int p,q;
        for(int i=0;i<m;i++){
            t += a[(R+i)%n];
        }
        mx = t;
        p = R;
        q = (R+m)%n;
        while((q+m-1)%m!=L){
            t -= a[p];
            t += a[q];
            p++;
            q++;
            p%=n;
            q%=n;
            chmax(mx,t);
        }
    }
    cout << mx - (sm-mx) << endl;
    return 0;
}
0