結果

問題 No.150 "良問"(良問とは言っていない
コンテスト
ユーザー uafr_cs
提出日時 2015-08-06 19:32:42
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 105 ms / 5,000 ms
コード長 1,202 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,638 ms
コンパイル使用メモリ 82,752 KB
実行使用メモリ 44,356 KB
最終ジャッジ日時 2026-04-27 07:46:37
合計ジャッジ時間 4,327 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {
	
	public static int problem_dfs(int start, char[] input){
		final char[] problem = "problem".toCharArray();
		
		int min = problem.length;
		for(int i = start; i <= input.length - problem.length; i++){
			int count = 0;
			
			for(int j = 0; j < problem.length; j++){
				if(input[i + j] != problem[j]){
					count++;
				}
			}
			
			min = Math.min(min, count);
		}
		
		return min;
	}
	
	public static int good_dfs(char[] input){
		final char[] good = "good".toCharArray();
		
		int min = "goodproblem".length();
		for(int i = 0; i <= input.length - "goodproblem".length(); i++){
			int count = 0;
			
			for(int j = 0; j < good.length; j++){
				if(input[i + j] != good[j]){
					count++;
				}
			}
			
			min = Math.min(min, count + problem_dfs(i + good.length, input));
		}
		
		return min;
	}
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final int T = sc.nextInt();
		
		for(int i = 0; i < T; i++){
			final char[] input = sc.next().toCharArray();
			
			System.out.println(good_dfs(input));
		}
	}
	
}
0