結果
問題 | No.672 最長AB列 |
ユーザー | Tsukasa_Type |
提出日時 | 2018-05-18 01:18:17 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 907 bytes |
コンパイル時間 | 1,998 ms |
コンパイル使用メモリ | 74,668 KB |
実行使用メモリ | 76,056 KB |
最終ジャッジ日時 | 2023-09-10 22:46:50 |
合計ジャッジ時間 | 6,998 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 115 ms
55,504 KB |
testcase_01 | AC | 114 ms
55,072 KB |
testcase_02 | AC | 114 ms
53,604 KB |
testcase_03 | AC | 115 ms
55,776 KB |
testcase_04 | AC | 114 ms
55,344 KB |
testcase_05 | AC | 110 ms
53,308 KB |
testcase_06 | AC | 117 ms
55,788 KB |
testcase_07 | AC | 119 ms
55,340 KB |
testcase_08 | WA | - |
testcase_09 | AC | 347 ms
76,056 KB |
testcase_10 | AC | 299 ms
67,188 KB |
testcase_11 | AC | 288 ms
63,320 KB |
testcase_12 | WA | - |
testcase_13 | AC | 270 ms
59,056 KB |
testcase_14 | WA | - |
testcase_15 | AC | 272 ms
58,736 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 256 ms
58,484 KB |
ソースコード
import static java.lang.System.*; import java.util.*; public class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { String s = sc.next(); int n = s.length(); int[] ar = new int[n+1]; int numA = 0; int numB = 0; for (int i=0; i<n; i++) { if (s.charAt(i)=='A') { numA++; ar[i+1] = Math.abs(numA-numB); } else { numB++; ar[i+1] = Math.abs(numA-numB); } } // for (int i=1; i<s.length(); i++) { // ar[i] += ar[i-1]; // } //0について調べるなら、一番左端の0と一番右端の0のみ考えればよい。 Map<Integer,Integer> map = new HashMap<>(); int max = 0; for (int i=0; i<n+1; i++) { if (map.containsKey(ar[i])) { max = Math.max(max,Math.abs(map.get(ar[i])-i)); } else { map.put(ar[i],i); } } out.println(max); // map.forEach((k,v)->out.println(k+":"+v)); } }