結果

問題 No.672 最長AB列
ユーザー butsurizukibutsurizuki
提出日時 2018-06-15 12:19:29
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 435 bytes
コンパイル時間 128 ms
コンパイル使用メモリ 28,204 KB
実行使用メモリ 4,472 KB
最終ジャッジ日時 2023-09-13 04:34:17
合計ジャッジ時間 1,165 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,472 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 3 ms
4,396 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<string.h>

int max(int a,int b){if(a>b){return a;}return b;}

int main(){
    int rs=0,i,rw[524288],res=0,l;
    char s[524288];
    for(i=0;i<524288;i++){rw[i]=-1;}
    rw[250000]=0;
    scanf("%s",s);
    l=strlen(s);
    for(i=1;i<=l;i++){
        if(s[i-1]=='A'){rs++;}else{rs--;}
        if(rw[250000+rs]==-1){rw[250000+rs]=i;}
        else{res=max(res,i-rw[250000+rs]);}
    }
    printf("%d\n",res);
}
0