結果

問題 No.150 "良問"(良問とは言っていない
ユーザー square1001square1001
提出日時 2017-03-09 14:45:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 866 bytes
コンパイル時間 873 ms
コンパイル使用メモリ 75,460 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-01 10:13:10
合計ジャッジ時間 2,050 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,388 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int Q; string s, t1 = "good", t2 = "problem";
int main() {
	cin >> Q;
	while (Q--) {
		cin >> s;
		vector<vector<int> > sum(8, vector<int>(s.size() + 1));
		for (int i = 0; i <= s.size() - 7; i++) {
			int cnt = 0;
			for (int j = 0; j < 7; j++) {
				if (s[i + j] != t2[j]) cnt++;
			}
			sum[cnt][i + 1]++;
		}
		for (int i = 0; i <= 7; i++) {
			for (int j = 0; j < s.size(); j++) {
				sum[i][j + 1] += sum[i][j];
			}
		}
		int ret = 999999999;
		for (int i = 0; i <= s.size() - 11; i++) {
			int cnt = 0;
			for (int j = 0; j < 4; j++) {
				if (s[i + j] != t1[j]) cnt++;
			}
			for (int j = 0; j <= 7; j++) {
				if (sum[j][s.size()] - sum[j][i + 4]) {
					ret = min(ret, cnt + j);
				}
			}
			if (cnt == 0) break;
		}
		cout << ret << endl;
	}
	return 0;
}
0