結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー GrenacheGrenache
提出日時 2015-07-27 16:16:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 529 ms / 2,000 ms
コード長 2,317 bytes
コンパイル時間 4,667 ms
コンパイル使用メモリ 76,236 KB
実行使用メモリ 69,648 KB
最終ジャッジ日時 2023-09-23 03:57:54
合計ジャッジ時間 6,346 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 312 ms
57,004 KB
testcase_01 AC 529 ms
69,648 KB
testcase_02 AC 297 ms
65,536 KB
testcase_03 AC 245 ms
68,664 KB
testcase_04 AC 252 ms
67,860 KB
testcase_05 AC 236 ms
67,932 KB
testcase_06 AC 45 ms
49,644 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_yukicoder252_1 {

    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];
        	int[] p0 = new int[n];
        	for (int j = 0; j + 6 < n; j++) {
        		if (j > 0) {
        			p0[j] = p0[j - 1];
        		}
        		p[j] = ham(s, j, "problem");
        		if (p[j] == 0) {
        			p0[j]++;
        		}
        	}
        	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] + (j >= 10 ? p0[j - 10] : 0));
        	}
        	
        	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