結果
問題 | No.672 最長AB列 |
ユーザー |
![]() |
提出日時 | 2020-09-04 09:05:06 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 305 ms / 2,000 ms |
コード長 | 652 bytes |
コンパイル時間 | 2,125 ms |
コンパイル使用メモリ | 74,752 KB |
実行使用メモリ | 70,152 KB |
最終ジャッジ日時 | 2024-11-25 01:29:10 |
合計ジャッジ時間 | 6,941 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); char[] arr = sc.next().toCharArray(); int current = 0; int max = 0; HashMap<Integer, Integer> places = new HashMap<>(); places.put(0, -1); for (int i = 0; i < arr.length; i++) { if (arr[i] == 'A') { current++; } else { current--; } if (places.containsKey(current)) { max = Math.max(max, i - places.get(current)); } else { places.put(current, i); } } System.out.println(max); } }