結果

問題 No.150 "良問"(良問とは言っていない
ユーザー uafr_csuafr_cs
提出日時 2015-08-06 19:32:42
言語 Java
(openjdk 23)
結果
AC  
実行時間 206 ms / 5,000 ms
コード長 1,202 bytes
コンパイル時間 2,181 ms
コンパイル使用メモリ 77,440 KB
実行使用メモリ 42,316 KB
最終ジャッジ日時 2024-10-11 01:56:00
合計ジャッジ時間 6,514 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

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