結果
問題 | No.672 最長AB列 |
ユーザー | Naco |
提出日時 | 2019-10-21 17:23:07 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 448 bytes |
コンパイル時間 | 1,722 ms |
コンパイル使用メモリ | 171,180 KB |
実行使用メモリ | 13,548 KB |
最終ジャッジ日時 | 2023-09-15 15:04:42 |
合計ジャッジ時間 | 3,165 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | WA | - |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 1 ms
4,380 KB |
testcase_09 | AC | 84 ms
13,548 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 19 ms
4,380 KB |
testcase_14 | WA | - |
testcase_15 | AC | 19 ms
4,384 KB |
testcase_16 | AC | 19 ms
4,384 KB |
testcase_17 | AC | 59 ms
8,956 KB |
testcase_18 | WA | - |
ソースコード
#include<bits/stdc++.h> using namespace std; int main(){ string s; cin >> s; int N=s.size(); int cnt[N+1]={}; for(int i=0;i<N;i++){ if(s[i]=='A') cnt[i]++; else cnt[i]--; } for(int i=1;i<N;i++){ cnt[i]+=cnt[i-1]; } map<int,int> m; for(int i=0;i<N;i++){ m[cnt[i]]=i; } int ans=0; for(int i=0;i<N;i++){ ans=max(m[cnt[i]]-i,ans); } cout << ans << endl; }