結果

問題 No.150 "良問"(良問とは言っていない
ユーザー uafr_csuafr_cs
提出日時 2015-08-06 19:32:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 194 ms / 5,000 ms
コード長 1,202 bytes
コンパイル時間 2,178 ms
コンパイル使用メモリ 78,212 KB
実行使用メモリ 42,036 KB
最終ジャッジ日時 2024-04-19 09:26:29
合計ジャッジ時間 6,041 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 164 ms
41,592 KB
testcase_01 AC 129 ms
41,444 KB
testcase_02 AC 122 ms
40,992 KB
testcase_03 AC 128 ms
40,944 KB
testcase_04 AC 127 ms
41,392 KB
testcase_05 AC 116 ms
41,468 KB
testcase_06 AC 194 ms
41,632 KB
testcase_07 AC 119 ms
40,988 KB
testcase_08 AC 130 ms
41,500 KB
testcase_09 AC 121 ms
41,336 KB
testcase_10 AC 178 ms
41,760 KB
testcase_11 AC 181 ms
41,740 KB
testcase_12 AC 163 ms
41,916 KB
testcase_13 AC 173 ms
41,720 KB
testcase_14 AC 175 ms
41,592 KB
testcase_15 AC 165 ms
42,036 KB
testcase_16 AC 125 ms
41,768 KB
testcase_17 AC 153 ms
41,296 KB
testcase_18 AC 170 ms
41,536 KB
testcase_19 AC 163 ms
41,372 KB
testcase_20 AC 162 ms
41,168 KB
権限があれば一括ダウンロードができます

ソースコード

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