結果

問題 No.150 "良問"(良問とは言っていない
ユーザー GrenacheGrenache
提出日時 2015-07-27 18:11:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 81 ms / 5,000 ms
コード長 2,130 bytes
コンパイル時間 3,504 ms
コンパイル使用メモリ 79,176 KB
実行使用メモリ 38,200 KB
最終ジャッジ日時 2024-04-19 09:26:15
合計ジャッジ時間 5,514 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
37,332 KB
testcase_01 AC 50 ms
37,084 KB
testcase_02 AC 51 ms
37,020 KB
testcase_03 AC 51 ms
36,800 KB
testcase_04 AC 52 ms
36,664 KB
testcase_05 AC 52 ms
36,800 KB
testcase_06 AC 81 ms
38,200 KB
testcase_07 AC 52 ms
36,884 KB
testcase_08 AC 51 ms
37,064 KB
testcase_09 AC 53 ms
36,960 KB
testcase_10 AC 58 ms
36,964 KB
testcase_11 AC 60 ms
37,496 KB
testcase_12 AC 57 ms
37,320 KB
testcase_13 AC 59 ms
37,312 KB
testcase_14 AC 62 ms
37,596 KB
testcase_15 AC 60 ms
36,808 KB
testcase_16 AC 53 ms
37,112 KB
testcase_17 AC 55 ms
37,220 KB
testcase_18 AC 63 ms
37,068 KB
testcase_19 AC 66 ms
37,180 KB
testcase_20 AC 64 ms
37,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Iterator;


public class Main_yukicoder150 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        for (int i = 0; i < t; i++) {
        	char[] s = sc.next().toCharArray();
        	int n = s.length;
        	
        	int[] p = new int[n];
        	for (int j = 0; j + 6 < n; j++) {
        		p[j] = ham(s, j, "problem");
        	}
        	for (int j = n - 7; j >= 0; j--) {
        		if (j < n - 7) {
        			p[j] = Math.min(p[j + 1], p[j]);
        		}
        	}
        	
        	int min = Integer.MAX_VALUE;
        	for (int j = 4; j + 6 < n; j++) {
        		int g = ham(s, j - 4, "good");
        		min = Math.min(min, g + p[j]);
        	}
        	
        	System.out.println(min);
        }

        sc.close();
    }

	private static int ham(char[] s, int j, String string) {
		char[] tmp = string.toCharArray();
		
		int ret = 0;
		for (int i = 0; i < tmp.length; i++) {
			if (s[j + i] != tmp[i]) {
				ret++;
			}
		}

		return ret;
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;
		
		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}
		
		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
					it = Arrays.asList(br.readLine().split(" ")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}
		
		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}

		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

		double nextDouble() throws RuntimeException {
			return Double.parseDouble(next());
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}
}
0