結果
| 問題 | No.672 最長AB列 |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2026-01-16 14:37:28 |
| 言語 | C++11(廃止可能性あり) (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 540 bytes |
| 記録 | |
| コンパイル時間 | 1,629 ms |
| コンパイル使用メモリ | 180,920 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-01-16 14:37:31 |
| 合計ジャッジ時間 | 2,942 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 6 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
const int N=4e5+7;
int o[N],x[N],y[N];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin>>s;
int n=s.size();
s=" "+s;
for(int i=1;i<=n;i++)
{
x[i]=x[i-1]+(s[i]=='A');
y[i]=y[i-1]+(s[i]=='B');
}
int p=200000;
for(int i=1;i<=400000;i++)
{
o[i]=n+1;
}
for(int i=1;i<=n;i++)
{
int a=x[i]-y[i]+p;
if(o[a]==n+1) o[a]=i;
}
int maxx=0;
for(int r=1;r<=n;r++)
{
int a=x[r]-y[r]+p;
if(o[a]<r)
{
maxx=max(maxx,r-o[a]);
}
}
cout<<maxx;
return 0;
}
vjudge1