結果
| 問題 |
No.150 "良問"(良問とは言っていない
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-07-27 18:11:14 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 83 ms / 5,000 ms |
| コード長 | 2,130 bytes |
| コンパイル時間 | 3,722 ms |
| コンパイル使用メモリ | 78,504 KB |
| 実行使用メモリ | 38,420 KB |
| 最終ジャッジ日時 | 2024-10-11 01:55:46 |
| 合計ジャッジ時間 | 5,788 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
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();
}
}
}
}