結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー DriceDrice
提出日時 2020-08-07 23:00:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 2,285 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 32,612 KB
実行使用メモリ 5,964 KB
最終ジャッジ日時 2023-10-25 04:05:46
合計ジャッジ時間 2,268 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<cstdio>
long long a[100005];
int vis[100005];
int bad[100005], good[100005];
long long sum[100005];

long long min(long long a,long long b){ return a>b?b:a; }

long long max(long long a,long long b){ return a>b?a:b; }

void doMove(int s,int t,int n,int da,int db){
    for(int i = 0; i < n; i++) vis[i] = 0;
    vis[s] = vis[t] = 1;
    good[s] = 1, bad[t] = 1;
    int pa = s, pb = t;
    while(true){
        int na = pa+da, nb = pb+db;
        if(na>=n) na -= n;
        if(nb>=n) nb -= n;
        if(na<0) na += n;
        if(nb<0) nb += n;
        if(vis[na] && vis[nb]) break;
        if(!vis[na]){
            vis[na] = 1;
            good[na] = 1;
        }
        if(!vis[nb]){
            vis[nb] = 1;
            bad[nb] = 1;
        }
        pa = na, pb = nb;
    }
}

long long getSegmentSum(int p,int len,int n){
    long long res = 0;
    if(p+len-1>n){
        res += sum[n]-sum[p-1];
        len -= (n-p+1);
        p = 1;
    }
    res += sum[p+len-1]-sum[p-1];
    return res;
}

long long getSum(int l,int len,int n){
    long long res = 0;
    if(l+len-1>n-1){
        res += sum[n-1];
        if(l!=0) res -= sum[l-1];
        l = (l+len-1)%n;
        res += sum[l];
    }
    else{
        res += sum[l+len-1];
        if(l!=0) res -= sum[l-1];
    }
    return res;
}

int main(){
    int n,s,t;
    scanf("%d%d%d",&n,&s,&t);
    s--, t--;
    long long all = 0;
    for(int i = 0; i < n; i++){ 
        scanf("%lld",&a[i]);
        all += a[i];
    }
    sum[0] = a[0];
    for(int i = 1; i < n; i++) sum[i] = sum[i-1]+a[i];
    doMove(s,t,n,1,-1);
    doMove(s,t,n,-1,1);
    /*for(int i = 0; i < n; i++) printf("%d",good[i]);
    printf("\n");
    for(int i = 0; i < n; i++) printf("%d",bad[i]);
    printf("\n");*/
    int have = n/2+n%2;
    long long ans = -1, fix = 0;
    for(int i = 0; i < n; i++){
        int l = s-i, r = s-i+have-1;
        l %= n, r %= n;
        if(l<0) l += n;
        if(r<0) r += n;
        if(good[l] && good[r]){
            long long cur = getSum(l,have,n);
            //printf("l = %d, cur = %lld\n",l,cur);
            cur = cur-(all-cur);
            if(!fix) ans = cur, fix = 1;
            else{
                if(cur>ans) ans = cur;
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}
0