結果
問題 |
No.672 最長AB列
|
ユーザー |
![]() |
提出日時 | 2018-04-13 22:43:28 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 757 bytes |
コンパイル時間 | 742 ms |
コンパイル使用メモリ | 94,148 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-13 00:24:42 |
合計ジャッジ時間 | 1,457 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 11 WA * 5 |
ソースコード
void main(){ import std.stdio, std.string, std.conv, std.algorithm; auto s=readln.chomp.to!(char[]); int n=s.length.to!(int); bool can(int len){ len+=(len&1); if(len>n) return false; int na=0, nb=0; foreach(i; 0..n){ if(i<len){ (s[i]=='A'?na:nb)+=1; }else{ (s[i-len]=='A'?na:nb)-=1; (s[i]=='A'?na:nb)+=1; } if(na==nb && na+nb>=len) return true; } return false; } int ok=-1, ng=n+1; while(ng-ok>1){ auto m=(ng+ok)/2; // writeln(ok, " ", m, " ", ng); (can(m)?ok:ng)=m; } writeln(ok); } void rd(T...)(ref T x){ import std.stdio, std.string, std.conv; auto l=readln.split; assert(l.length==x.length); foreach(i, ref e; x) e=l[i].to!(typeof(e)); }