結果

問題 No.355 数当てゲーム(2)
ユーザー krotonkroton
提出日時 2015-07-25 18:44:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,175 bytes
コンパイル時間 558 ms
コンパイル使用メモリ 66,932 KB
実行使用メモリ 24,372 KB
平均クエリ数 5.52
最終ジャッジ日時 2023-09-23 21:03:01
合計ジャッジ時間 4,590 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
24,360 KB
testcase_01 AC 25 ms
23,700 KB
testcase_02 AC 25 ms
23,556 KB
testcase_03 AC 25 ms
23,664 KB
testcase_04 AC 25 ms
23,424 KB
testcase_05 AC 26 ms
23,556 KB
testcase_06 AC 26 ms
24,060 KB
testcase_07 AC 25 ms
23,688 KB
testcase_08 AC 24 ms
24,072 KB
testcase_09 AC 26 ms
23,448 KB
testcase_10 AC 26 ms
24,360 KB
testcase_11 AC 24 ms
23,436 KB
testcase_12 AC 26 ms
24,348 KB
testcase_13 AC 25 ms
24,288 KB
testcase_14 AC 26 ms
24,108 KB
testcase_15 AC 26 ms
23,448 KB
testcase_16 AC 25 ms
23,448 KB
testcase_17 AC 26 ms
24,084 KB
testcase_18 AC 25 ms
23,604 KB
testcase_19 AC 26 ms
23,664 KB
testcase_20 AC 26 ms
23,736 KB
testcase_21 AC 26 ms
24,264 KB
testcase_22 AC 25 ms
24,348 KB
testcase_23 AC 25 ms
24,312 KB
testcase_24 AC 25 ms
23,628 KB
testcase_25 AC 25 ms
24,036 KB
testcase_26 AC 25 ms
23,388 KB
testcase_27 AC 28 ms
23,448 KB
testcase_28 AC 25 ms
24,024 KB
testcase_29 AC 25 ms
23,616 KB
testcase_30 AC 26 ms
23,448 KB
testcase_31 AC 27 ms
23,700 KB
testcase_32 AC 26 ms
24,024 KB
testcase_33 AC 25 ms
24,108 KB
testcase_34 AC 24 ms
23,604 KB
testcase_35 AC 25 ms
23,676 KB
testcase_36 AC 25 ms
24,096 KB
testcase_37 AC 25 ms
23,616 KB
testcase_38 AC 25 ms
24,372 KB
testcase_39 AC 24 ms
24,288 KB
testcase_40 AC 25 ms
23,868 KB
testcase_41 AC 26 ms
23,712 KB
testcase_42 AC 25 ms
23,448 KB
testcase_43 AC 25 ms
23,604 KB
testcase_44 AC 25 ms
24,048 KB
testcase_45 AC 25 ms
24,072 KB
testcase_46 AC 25 ms
23,868 KB
testcase_47 AC 25 ms
24,024 KB
testcase_48 AC 25 ms
23,688 KB
testcase_49 AC 26 ms
24,240 KB
testcase_50 AC 26 ms
24,072 KB
testcase_51 AC 25 ms
23,664 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(){
	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[0];

		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