結果

問題 No.150 "良問"(良問とは言っていない
ユーザー tentententen
提出日時 2021-02-03 14:15:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 175 ms / 5,000 ms
コード長 1,277 bytes
コンパイル時間 3,627 ms
コンパイル使用メモリ 74,512 KB
実行使用メモリ 56,556 KB
最終ジャッジ日時 2023-09-12 12:50:34
合計ジャッジ時間 8,019 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 160 ms
55,760 KB
testcase_01 AC 120 ms
55,640 KB
testcase_02 AC 122 ms
56,164 KB
testcase_03 AC 120 ms
55,888 KB
testcase_04 AC 122 ms
55,604 KB
testcase_05 AC 124 ms
55,728 KB
testcase_06 AC 175 ms
56,164 KB
testcase_07 AC 120 ms
55,644 KB
testcase_08 AC 121 ms
56,000 KB
testcase_09 AC 123 ms
55,864 KB
testcase_10 AC 151 ms
56,120 KB
testcase_11 AC 151 ms
56,028 KB
testcase_12 AC 149 ms
56,248 KB
testcase_13 AC 158 ms
55,600 KB
testcase_14 AC 150 ms
56,016 KB
testcase_15 AC 151 ms
55,960 KB
testcase_16 AC 127 ms
56,340 KB
testcase_17 AC 146 ms
55,932 KB
testcase_18 AC 175 ms
56,544 KB
testcase_19 AC 173 ms
56,408 KB
testcase_20 AC 172 ms
56,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] good = "good".toCharArray();
        int gLength = good.length;
        char[] problem = "problem".toCharArray();
        int pLength = problem.length;
        int t = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < t; i++) {
            char[] line = sc.next().toCharArray();
            int min = Integer.MAX_VALUE;
            for (int j = 0; j <= line.length - gLength - pLength; j++) {
                int gCount = 0;
                for (int k = 0; k < gLength; k++) {
                    if (good[k] != line[j + k]) {
                        gCount++;
                    }
                }
                for (int k = j + gLength; k <= line.length - pLength; k++) {
                    int pCount = 0;
                    for (int l = 0; l < pLength; l++) {
                        if (problem[l] != line[k + l]) {
                            pCount++;
                        }
                    }
                    min = Math.min(min, gCount + pCount);
                }
            }
            sb.append(min).append("\n");
        }
        System.out.print(sb);
    }
}
0