結果
問題 |
No.672 最長AB列
|
ユーザー |
![]() |
提出日時 | 2018-04-13 22:47:48 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 965 bytes |
コンパイル時間 | 741 ms |
コンパイル使用メモリ | 94,080 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-13 00:24:44 |
合計ジャッジ時間 | 1,761 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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){ 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; if(m&1){ auto res_l=can(m-1), res_r=can(m+1); if(res_l==true && res_r==false){ ok=m-1; break; }else if(res_l==true && res_r==true){ ok=m; }else if(res_l==false && res_r==false){ ng=m; } }else{ (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)); }