結果
| 問題 | No.672 最長AB列 |
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-05-02 12:33:40 |
| 言語 | C(gnu17) (gcc 15.2.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 629 bytes |
| 記録 | |
| コンパイル時間 | 220 ms |
| コンパイル使用メモリ | 38,720 KB |
| 最終ジャッジ日時 | 2026-02-22 03:14:55 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
// yukicoder: No.672 最長AB列
// 2019.5.2 bal4u
#include <stdio.h>
#include <ctype.h>
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int ins(char *s) // 文字列の入力 スペース以下の文字で入力終了
{
char *p = s;
do *s = gc();
while (*s++ > ' ');
*--s = 0;
return s - p;
}
#define MAX 200005
char S[MAX]; int w;
int f[MAX<<1];
int main()
{
int i, a, max;
w = ins(S+2)+2;
max = 0, a = MAX, f[a] = 1;
for (i = 2; i < w; i++) {
if (S[i] == 'A') a++; else a--;
if (f[a] == 0) f[a] = i;
else if (i - f[a] > max) max = i - f[a];
}
printf("%d\n", max);
return 0;
}
bal4u