結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
くれちー
|
| 提出日時 | 2018-04-13 23:09:21 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 744 bytes |
| コンパイル時間 | 285 ms |
| コンパイル使用メモリ | 102,272 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2024-11-30 12:16:18 |
| 合計ジャッジ時間 | 28,384 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 7 TLE * 9 |
ソースコード
#include <stdio.h>
#include <string.h>
#define S_MAX 200001
int main() {
char s[S_MAX];
scanf("%s", s);
int len = strlen(s);
int a[S_MAX] = { 0 }, b[S_MAX] = { 0 };
for (int i = len - 1; i >= 0; --i) {
if (s[i] == 'A') ++a[i];
else if (s[i] == 'B') ++b[i];
a[i] += a[i + 1];
b[i] += b[i + 1];
}
int ans = 0;
for (int i = 0; i < len - 1; ++i) {
int cnt = b[i] - a[i];
for (int j = len - 1; j >= i; --j) {
if (cnt == 0) {
if (j - i + 1 > ans) ans = j - i + 1;
break;
}
if (s[j] == 'A') ++cnt;
else if (s[j] == 'B') --cnt;
}
}
printf("%d\n", ans);
return 0;
}
くれちー