結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー mtsdmtsd
提出日時 2020-08-07 22:48:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,262 bytes
コンパイル時間 1,208 ms
コンパイル使用メモリ 118,996 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 03:39:41
合計ジャッジ時間 3,660 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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(1){
        if(!f){
            f = 1;
            b++;
            if(b>=n)b-=n;
            if(b==c){
                b--;
                if(b<0)b+=n;
                break;
            }
            if(abs(b-c)<=1||(b==n-1&&c==0)||(b==0&&c==n-1))break;
        }else{
            f = 0;
            c--;
            if(c<0)c+=n;
            if(abs(b-c)<=1||(b==n-1&&c==0)||(b==0&&c==n-1))break;
            
        }
    }
    L = b;
    b = s;
    c = t;
    f = 0;
    while(1){
        if(!f){
            f = 1;
            b--;
            if(b<0)b+=n;
            if(b==c){
                b++;
                if(b>=n)b-=n;
                break;
            }
            if(abs(b-c)<=1||(b==n-1&&c==0)||(b==0&&c==n-1))break;
                
        }else{
            f = 0;
            c++;
            if(c>=n)c-=n;
            if(abs(b-c)<=1||(b==n-1&&c==0)||(b==0&&c==n-1))break;
        
        }
    }
    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||(s==L&&(s+1)%n!=t)){
        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+n-1)%n!=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+n-1)%n!=L){
            t -= a[p];
            t += a[q];
            p++;
            q++;
            p%=n;
            q%=n;
            chmax(mx,t);
        }
    }
    // cerr << mx << endl;
    cout << mx - (sm-mx) << endl;
    return 0;
}
0