結果
問題 | No.672 最長AB列 |
ユーザー | ikd |
提出日時 | 2018-04-14 19:35:11 |
言語 | D (dmd 2.107.1) |
結果 |
AC
|
実行時間 | 126 ms / 2,000 ms |
コード長 | 773 bytes |
コンパイル時間 | 990 ms |
コンパイル使用メモリ | 78,004 KB |
実行使用メモリ | 34,764 KB |
最終ジャッジ日時 | 2023-09-03 19:28:24 |
合計ジャッジ時間 | 2,748 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 1 ms
4,384 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 1 ms
4,380 KB |
testcase_09 | AC | 126 ms
34,764 KB |
testcase_10 | AC | 55 ms
13,132 KB |
testcase_11 | AC | 58 ms
11,868 KB |
testcase_12 | AC | 15 ms
4,380 KB |
testcase_13 | AC | 17 ms
4,380 KB |
testcase_14 | AC | 16 ms
4,380 KB |
testcase_15 | AC | 15 ms
4,380 KB |
testcase_16 | AC | 16 ms
4,376 KB |
testcase_17 | AC | 54 ms
11,980 KB |
testcase_18 | AC | 14 ms
4,376 KB |
ソースコード
void main(){ import std.stdio, std.string, std.conv, std.algorithm; auto s=readln.chomp.to!(char[]); int[int] posl, posr; int n=s.length.to!(int), na=0, nb=0; posl[na-nb]=posr[na-nb]=0; foreach(int i; 0..n){ if(s[i]=='A') na++; if(s[i]=='B') nb++; auto dif=na-nb; if(dif in posl) chmin(posl[dif], i+1); else posl[dif]=i+1; if(dif in posr) chmax(posr[dif], i+1); else posr[dif]=i+1; } int len=0; foreach(k; posl.keys){ chmax(len, posr[k]-posl[k]); } writeln(len); } void chmin(T)(ref T l, T r){if(l>r)l=r;} void chmax(T)(ref T l, T r){if(l<r)l=r;} 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)); }