結果
| 問題 | No.672 最長AB列 |
| コンテスト | |
| ユーザー |
silviasetitech
|
| 提出日時 | 2020-03-15 15:43:07 |
| 言語 | Java (openjdk 27 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 131 ms / 2,000 ms |
| + 809µs | |
| コード長 | 1,474 bytes |
| 記録 | |
| コンパイル時間 | 1,530 ms |
| コンパイル使用メモリ | 86,352 KB |
| 実行使用メモリ | 49,372 KB |
| 最終ジャッジ日時 | 2026-09-29 14:35:08 |
| 合計ジャッジ時間 | 5,052 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author silviase
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
longestABSubString solver = new longestABSubString();
solver.solve(1, in, out);
out.close();
}
static class longestABSubString {
public void solve(int testNumber, Scanner in, PrintWriter out) {
String s = in.next();
int l = s.length();
int[] dif = new int[l * 2 + 2];
int now = l;
Arrays.fill(dif, -1);
dif[now] = 0;
int res = 0;
for (int i = 0; i < l; i++) {
if (s.charAt(i) == 'A') {
now++;
} else {
now--;
}
if (dif[now] == -1) {
// 更新する
dif[now] = i + 1;
} else {
// 比較する
res = Math.max(res, i + 1 - dif[now]);
}
}
out.println(res);
}
}
}
silviasetitech