結果

問題 No.150 "良問"(良問とは言っていない
ユーザー htensaihtensai
提出日時 2019-12-26 09:29:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 176 ms / 5,000 ms
コード長 1,541 bytes
コンパイル時間 2,552 ms
コンパイル使用メモリ 77,744 KB
実行使用メモリ 54,424 KB
最終ジャッジ日時 2024-04-14 06:11:46
合計ジャッジ時間 6,446 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
54,100 KB
testcase_01 AC 132 ms
54,140 KB
testcase_02 AC 134 ms
54,132 KB
testcase_03 AC 132 ms
54,020 KB
testcase_04 AC 131 ms
53,900 KB
testcase_05 AC 132 ms
54,164 KB
testcase_06 AC 176 ms
54,388 KB
testcase_07 AC 133 ms
54,132 KB
testcase_08 AC 131 ms
54,020 KB
testcase_09 AC 134 ms
54,240 KB
testcase_10 AC 143 ms
54,236 KB
testcase_11 AC 144 ms
54,176 KB
testcase_12 AC 140 ms
54,244 KB
testcase_13 AC 142 ms
54,276 KB
testcase_14 AC 143 ms
54,132 KB
testcase_15 AC 142 ms
54,144 KB
testcase_16 AC 133 ms
54,232 KB
testcase_17 AC 136 ms
54,196 KB
testcase_18 AC 165 ms
54,344 KB
testcase_19 AC 170 ms
54,424 KB
testcase_20 AC 171 ms
54,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final char[] GOOD = "good".toCharArray();
    static final char[] PROBLEM = "problem".toCharArray();
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int k = 0; k < t; k++) {
            char[] arr = sc.next().toCharArray();
            int length = arr.length;
            int size = length - 11 + 1;
            int[] gArr = new int[size];
            int[] pArr = new int[size];
            for (int i = 0; i < size; i++) {
                for (int j = 0; j < GOOD.length; j++) {
                    if (arr[i + j] != GOOD[j]) {
                        gArr[i]++;
                    }
                }
                if (i != 0) {
                    gArr[i] = Math.min(gArr[i - 1], gArr[i]);
                }
            }
             for (int i = size - 1; i >= 0; i--) {
                for (int j = 0; j < PROBLEM.length; j++) {
                    if (arr[i + GOOD.length + j] != PROBLEM[j]) {
                        pArr[i]++;
                    }
                }
                if (i != size - 1) {
                    pArr[i] = Math.min(pArr[i + 1], pArr[i]);
                }
            }
            int min = Integer.MAX_VALUE;
            for (int i = 0; i < size; i++) {
                min = Math.min(min, gArr[i] + pArr[i]);
            }
            sb.append(min).append("\n");
        }
        System.out.print(sb);
    }
}
0