結果
問題 | No.672 最長AB列 |
ユーザー | tenten |
提出日時 | 2022-08-02 14:24:55 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 222 ms / 2,000 ms |
コード長 | 1,422 bytes |
コンパイル時間 | 2,197 ms |
コンパイル使用メモリ | 74,468 KB |
実行使用メモリ | 70,296 KB |
最終ジャッジ日時 | 2023-09-30 14:00:47 |
合計ジャッジ時間 | 6,384 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
49,408 KB |
testcase_01 | AC | 44 ms
49,556 KB |
testcase_02 | AC | 45 ms
47,304 KB |
testcase_03 | AC | 44 ms
49,364 KB |
testcase_04 | AC | 44 ms
49,340 KB |
testcase_05 | AC | 44 ms
49,368 KB |
testcase_06 | AC | 44 ms
49,460 KB |
testcase_07 | AC | 45 ms
49,420 KB |
testcase_08 | AC | 44 ms
49,368 KB |
testcase_09 | AC | 222 ms
70,296 KB |
testcase_10 | AC | 191 ms
62,620 KB |
testcase_11 | AC | 186 ms
62,852 KB |
testcase_12 | AC | 160 ms
55,756 KB |
testcase_13 | AC | 164 ms
56,192 KB |
testcase_14 | AC | 165 ms
56,096 KB |
testcase_15 | AC | 162 ms
55,880 KB |
testcase_16 | AC | 162 ms
55,332 KB |
testcase_17 | AC | 182 ms
60,252 KB |
testcase_18 | AC | 144 ms
52,980 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); HashMap<Integer, Integer> places = new HashMap<>(); places.put(0, 0); int current = 0; int ans = 0; int idx = 1; for (char c : sc.next().toCharArray()) { if (c =='A') { current++; } else { current--; } if (places.containsKey(current)) { ans = Math.max(ans, idx - places.get(current)); } else { places.put(current, idx); } idx++; } System.out.println(ans); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }