結果
問題 | No.672 最長AB列 |
ユーザー |
![]() |
提出日時 | 2020-03-15 15:43:07 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 204 ms / 2,000 ms |
コード長 | 1,474 bytes |
コンパイル時間 | 2,157 ms |
コンパイル使用メモリ | 77,640 KB |
実行使用メモリ | 56,640 KB |
最終ジャッジ日時 | 2024-11-25 02:06:46 |
合計ジャッジ時間 | 5,877 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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);}}}