結果

問題 No.672 最長AB列
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2018-04-13 23:17:58
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 950 bytes
コンパイル時間 2,244 ms
コンパイル使用メモリ 75,828 KB
実行使用メモリ 69,740 KB
最終ジャッジ日時 2023-09-10 00:57:47
合計ジャッジ時間 8,656 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

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');
System.out.println("A="+A + " B="+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