結果

問題 No.150 "良問"(良問とは言っていない
ユーザー startcppstartcpp
提出日時 2015-02-13 00:06:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 865 bytes
コンパイル時間 507 ms
コンパイル使用メモリ 56,988 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 09:14:33
合計ジャッジ時間 1,448 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 6 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:22:64: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
   22 |                                 int hamming1 = gethamming(S+j, "good", 4);
      |                                                                ^~~~~~
main.cpp:23:64: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
   23 |                                 int hamming2 = gethamming(S+k, "problem", 7);
      |                                                                ^~~~~~~~~

ソースコード

diff #

//想定解法O(T|S|)、何を全探索するかが肝心。
//ちなみに、想定TLE解はO(26^答え)
#include<iostream>
#include<string.h>
using namespace std;

int gethamming(char *str1, char *str2, int n);

int T;
char S[102];

int main() {
	int i, j, k;
	cin >> T;
	for( i = 0; i < T; i++ ) {
		cin >> S;
		int slen = strlen(S);
		int ans = 114514;
		for( j = 0; j <= slen - 11; j++ ) {
			//k>=j+4、k>=jでやるとWrongAnswerするようにテストケース作った(はずなので後で試す
			for( k = j+4; k <= slen - 7; k++ ) {
				int hamming1 = gethamming(S+j, "good", 4);
				int hamming2 = gethamming(S+k, "problem", 7);
				ans = min(ans, hamming1 + hamming2);
			}
		}
		cout << ans << endl;
	}
}
int gethamming(char *str1, char *str2, int n) {
	int i, ret = 0;
	for( i = 0; i < n; i++ ) {
		ret += ( str1[i] != str2[i] );
	}
	return ret;
}
0