結果

問題 No.355 数当てゲーム(2)
ユーザー masamasa
提出日時 2016-04-02 00:18:18
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,754 bytes
コンパイル時間 544 ms
コンパイル使用メモリ 69,324 KB
実行使用メモリ 24,420 KB
平均クエリ数 29.42
最終ジャッジ日時 2023-09-23 09:59:39
合計ジャッジ時間 6,723 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,376 KB
testcase_01 AC 25 ms
23,556 KB
testcase_02 WA -
testcase_03 AC 24 ms
23,844 KB
testcase_04 AC 25 ms
23,388 KB
testcase_05 AC 24 ms
23,544 KB
testcase_06 WA -
testcase_07 AC 25 ms
24,072 KB
testcase_08 AC 24 ms
23,436 KB
testcase_09 AC 24 ms
23,412 KB
testcase_10 WA -
testcase_11 AC 23 ms
24,048 KB
testcase_12 AC 24 ms
23,388 KB
testcase_13 AC 25 ms
23,832 KB
testcase_14 AC 23 ms
23,616 KB
testcase_15 AC 24 ms
24,348 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 24 ms
24,312 KB
testcase_19 AC 24 ms
23,388 KB
testcase_20 WA -
testcase_21 AC 24 ms
23,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 23 ms
23,640 KB
testcase_25 AC 23 ms
24,072 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 23 ms
24,036 KB
testcase_30 AC 25 ms
23,376 KB
testcase_31 AC 26 ms
24,036 KB
testcase_32 AC 25 ms
23,376 KB
testcase_33 WA -
testcase_34 AC 27 ms
23,520 KB
testcase_35 AC 24 ms
24,396 KB
testcase_36 AC 23 ms
23,844 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 24 ms
23,388 KB
testcase_45 AC 24 ms
23,388 KB
testcase_46 AC 23 ms
24,036 KB
testcase_47 WA -
testcase_48 AC 24 ms
23,832 KB
testcase_49 WA -
testcase_50 AC 24 ms
23,544 KB
testcase_51 AC 23 ms
24,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

pair<int, int> ask(vector<int> &v) {
	printf("%d %d %d %d", v[0], v[1], v[2], v[3]);
	cout << endl;
	int x, y;
	cin >> x >> y;
	return make_pair(x, y);
}

vector<int> make_rests(vector<int> v) {
	vector<int> rests;
	for (int i = 0; i < 10; i++) {
		if (find(v.begin(), v.end(), i) == v.end()) {
			rests.emplace_back(i);
		}
	}

	return rests;
}

vector<int> search_by_type(vector<int> rests, int type) {
	vector<int> nums;

	for (int i = (1 << 6) - 1; i >= 0; i--) {
		if (__builtin_popcount(i) != 4) {
			continue;
		}

		nums.clear();

		for (int j = 0; j < 6; j++) {
			if ((i >> j) & 1) {
				nums.emplace_back(rests[j]);
			}
		}
		auto p = ask(nums);
		int sum = p.first + p.second;

		if (type == 0 && sum == 0) {
			return nums;
		} else if (type == 1 && sum >= 2) {
			return nums;
		}
	}

	return nums;
}

vector<int> search_0() {
	vector<int> nums = {0, 1, 2, 3};
	auto p = ask(nums);
	if (p.first == 4) {
		exit(0);
	}

	int sum = p.first + p.second;

	if (sum == 0) {
		return nums;
	}

	if (sum == 1) {
		auto rests = make_rests(nums);
		nums = search_by_type(rests, 2);
		rests = make_rests(nums);
		nums = search_by_type(rests, 2);
		return nums;
	}

	if (sum >= 2) {
		auto rests = make_rests(nums);
		nums = search_by_type(rests, 0);
		return nums;
	}

	return nums;
}

int main() {
	auto nums = search_0();
	auto rests = make_rests(nums);

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 6; j++) {
			if (find(nums.begin(), nums.end(), rests[j]) != nums.end()) {
				continue;
			}
			nums[i] = rests[j];
			auto p = ask(nums);
			if (p.first == i + 1) {
				break;
			}
		}
	}

	return 0;
}
0