結果

問題 No.672 最長AB列
ユーザー kohaku_kohaku
提出日時 2018-04-13 23:18:29
言語 Java
(openjdk 23)
結果
TLE  
実行時間 -
コード長 912 bytes
コンパイル時間 2,603 ms
コンパイル使用メモリ 74,124 KB
実行使用メモリ 52,448 KB
最終ジャッジ日時 2024-06-27 17:25:33
合計ジャッジ時間 7,464 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 TLE * 1 -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int ans = function(s);
        System.out.println(ans);
    }
    
    static int function(String s) {
        for(int i = s.length(); i >=0; i--) {
            for(int j = 0; j < s.length()-i+1; j++) {
                String tmp = s.substring(j,i+j);
                if(judge(tmp)) return i;
            }
        }
        return 0;
    }
    
    static boolean judge(String s) {
        int A = count(s,'A');
        int B = count(s,'B');
        if(A == B) {
            return true;
        } else {
            return false;
        }
    }
    
    static int count(String s, char c) {
        int count = 0;
        for(int i = 0; i <s.length(); i++) {
            if(s.charAt(i) == c) count++;
        }
        return count;
    }
}
0