結果

問題 No.672 最長AB列
ユーザー fal_rndfal_rnd
提出日時 2018-04-13 23:58:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 505 ms / 2,000 ms
コード長 514 bytes
コンパイル時間 2,461 ms
コンパイル使用メモリ 84,024 KB
実行使用メモリ 91,956 KB
最終ジャッジ日時 2023-09-10 04:16:22
合計ジャッジ時間 8,517 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,708 KB
testcase_01 AC 129 ms
55,900 KB
testcase_02 AC 129 ms
55,852 KB
testcase_03 AC 129 ms
55,736 KB
testcase_04 AC 129 ms
55,812 KB
testcase_05 AC 129 ms
55,764 KB
testcase_06 AC 129 ms
55,944 KB
testcase_07 AC 129 ms
56,112 KB
testcase_08 AC 129 ms
55,820 KB
testcase_09 AC 505 ms
91,956 KB
testcase_10 AC 451 ms
82,424 KB
testcase_11 AC 464 ms
79,828 KB
testcase_12 AC 321 ms
59,260 KB
testcase_13 AC 331 ms
57,424 KB
testcase_14 AC 322 ms
58,780 KB
testcase_15 AC 324 ms
59,136 KB
testcase_16 AC 314 ms
59,216 KB
testcase_17 AC 435 ms
76,448 KB
testcase_18 AC 305 ms
59,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main{
	public static void main(String[]$){
		Scanner s=new Scanner(System.in);
		char[]v=s.next().toCharArray();
		int n=v.length,d[]=new int[n+1];
		for(int i=0;i<n;++i)
			d[i+1]=d[i]+(v[i]=='A'?1:-1);
		
		Map<Integer,Integer> l=new HashMap<>(),r=new HashMap<>();
		for(int i=0;i<n+1;++i){
			l.merge(d[i],i,Math::min);
			r.merge(d[i],i,Math::max);
		}
		System.out.println(r.keySet().stream()
				.map(i->r.get(i)-l.getOrDefault(i,1<<20))
				.mapToInt(o->o).max().getAsInt());
	}
}
0