結果

問題 No.355 数当てゲーム(2)
ユーザー krotonkroton
提出日時 2015-07-25 18:37:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,185 bytes
コンパイル時間 616 ms
コンパイル使用メモリ 66,520 KB
実行使用メモリ 24,468 KB
平均クエリ数 5.23
最終ジャッジ日時 2023-09-23 21:02:42
合計ジャッジ時間 4,976 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
24,288 KB
testcase_01 AC 26 ms
23,688 KB
testcase_02 AC 26 ms
23,412 KB
testcase_03 AC 26 ms
23,436 KB
testcase_04 AC 26 ms
23,688 KB
testcase_05 AC 26 ms
23,664 KB
testcase_06 AC 27 ms
23,424 KB
testcase_07 AC 26 ms
23,436 KB
testcase_08 AC 27 ms
24,372 KB
testcase_09 AC 25 ms
23,868 KB
testcase_10 AC 25 ms
24,360 KB
testcase_11 AC 26 ms
23,880 KB
testcase_12 AC 26 ms
24,468 KB
testcase_13 AC 26 ms
24,276 KB
testcase_14 AC 26 ms
24,384 KB
testcase_15 AC 26 ms
23,688 KB
testcase_16 AC 26 ms
23,424 KB
testcase_17 AC 27 ms
24,348 KB
testcase_18 AC 26 ms
24,084 KB
testcase_19 AC 27 ms
23,724 KB
testcase_20 AC 26 ms
23,412 KB
testcase_21 AC 26 ms
24,324 KB
testcase_22 AC 25 ms
23,460 KB
testcase_23 AC 24 ms
23,412 KB
testcase_24 AC 25 ms
24,072 KB
testcase_25 AC 26 ms
23,676 KB
testcase_26 AC 25 ms
24,372 KB
testcase_27 AC 24 ms
23,868 KB
testcase_28 AC 25 ms
24,336 KB
testcase_29 AC 24 ms
23,568 KB
testcase_30 AC 25 ms
23,436 KB
testcase_31 AC 25 ms
23,580 KB
testcase_32 AC 25 ms
23,448 KB
testcase_33 AC 26 ms
23,448 KB
testcase_34 AC 25 ms
23,448 KB
testcase_35 AC 26 ms
23,460 KB
testcase_36 AC 25 ms
24,264 KB
testcase_37 AC 26 ms
23,568 KB
testcase_38 AC 24 ms
24,384 KB
testcase_39 AC 25 ms
24,060 KB
testcase_40 AC 25 ms
24,084 KB
testcase_41 AC 24 ms
24,048 KB
testcase_42 AC 24 ms
23,580 KB
testcase_43 AC 25 ms
23,544 KB
testcase_44 AC 26 ms
23,676 KB
testcase_45 AC 24 ms
24,312 KB
testcase_46 AC 26 ms
24,396 KB
testcase_47 AC 25 ms
23,664 KB
testcase_48 AC 24 ms
23,568 KB
testcase_49 AC 24 ms
24,324 KB
testcase_50 AC 24 ms
23,424 KB
testcase_51 AC 25 ms
24,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <tuple>
using namespace std;

pair<int, int> judge(const string& ans, const string& challenge){
	int h = 0, b = 0;
	for(int i=0;i<4;i++){
		if(challenge[i] == ans[i]){
			++h;
		} else if(ans.find(challenge[i]) != string::npos){
			++b;
		}
	}
	return make_pair(h, b);
}

pair<int, int> ask(const string& S){
	cout << S[0] << " " << S[1] << " " << S[2] << " " << S[3] << endl;
	int h, b;
	cin >> h >> b;
	return make_pair(h, b);
}

const pair<int, int> last = make_pair(4, 0);

int main(){
	srand(1);

	vector<string> cand;
	for(char a='0';a<='9';a++){
		for(char b='0';b<='9';b++)if(b != a){
			for(char c='0';c<='9';c++)if(c != a && c != b){
				for(char d='0';d<='9';d++)if(d != a && d != b && d != c){
					string num = "";
					num += a;
					num += b;
					num += c;
					num += d;
					cand.push_back(num);
				}
			}
		}
	}

	int size = cand.size();
	for(;;){
		int r = rand() % size;
		string challenge = cand[r];

		auto res = ask(challenge);
		if(res == last){
			break;
		}

		int j = 0;
		for(int i=0;i<size;i++){
			if(judge(cand[i], challenge) == res){
				cand[j] = cand[i];
				++j;
			}
		}

		size = j;
	}
	return 0;
}
0