結果

問題 No.355 数当てゲーム(2)
ユーザー hanorverhanorver
提出日時 2016-04-02 14:59:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,881 bytes
コンパイル時間 471 ms
コンパイル使用メモリ 68,784 KB
実行使用メモリ 24,408 KB
平均クエリ数 26.62
最終ジャッジ日時 2023-09-23 23:35:17
合計ジャッジ時間 3,956 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
23,436 KB
testcase_01 AC 21 ms
23,568 KB
testcase_02 AC 21 ms
23,868 KB
testcase_03 AC 21 ms
24,048 KB
testcase_04 AC 22 ms
23,556 KB
testcase_05 AC 19 ms
23,400 KB
testcase_06 AC 20 ms
23,400 KB
testcase_07 AC 22 ms
24,036 KB
testcase_08 AC 25 ms
24,024 KB
testcase_09 AC 23 ms
24,036 KB
testcase_10 AC 23 ms
23,652 KB
testcase_11 AC 21 ms
24,048 KB
testcase_12 AC 21 ms
23,412 KB
testcase_13 AC 21 ms
24,360 KB
testcase_14 AC 20 ms
23,664 KB
testcase_15 AC 22 ms
24,324 KB
testcase_16 AC 21 ms
23,652 KB
testcase_17 AC 20 ms
23,820 KB
testcase_18 AC 19 ms
24,024 KB
testcase_19 AC 21 ms
23,400 KB
testcase_20 AC 22 ms
23,376 KB
testcase_21 AC 21 ms
23,664 KB
testcase_22 AC 20 ms
24,192 KB
testcase_23 AC 20 ms
24,060 KB
testcase_24 AC 20 ms
23,664 KB
testcase_25 AC 21 ms
23,664 KB
testcase_26 AC 21 ms
24,324 KB
testcase_27 AC 20 ms
23,436 KB
testcase_28 AC 21 ms
23,376 KB
testcase_29 AC 22 ms
24,048 KB
testcase_30 AC 21 ms
24,072 KB
testcase_31 AC 21 ms
23,652 KB
testcase_32 AC 23 ms
24,036 KB
testcase_33 AC 20 ms
24,204 KB
testcase_34 AC 21 ms
24,408 KB
testcase_35 AC 19 ms
24,384 KB
testcase_36 AC 20 ms
23,400 KB
testcase_37 AC 22 ms
23,376 KB
testcase_38 AC 20 ms
24,204 KB
testcase_39 AC 20 ms
23,400 KB
testcase_40 AC 23 ms
23,652 KB
testcase_41 AC 23 ms
24,396 KB
testcase_42 AC 20 ms
23,556 KB
testcase_43 AC 20 ms
23,412 KB
testcase_44 AC 20 ms
24,048 KB
testcase_45 AC 19 ms
24,060 KB
testcase_46 AC 19 ms
23,448 KB
testcase_47 AC 20 ms
24,048 KB
testcase_48 AC 21 ms
23,976 KB
testcase_49 AC 20 ms
24,048 KB
testcase_50 AC 23 ms
24,360 KB
testcase_51 AC 21 ms
23,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:53:7: warning: ‘pre’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     c = pre;
     ~~^~~~~

ソースコード

diff #

#include<iostream>
#include<climits>
#include<vector>
#include<algorithm>

void print(int a, int b, int c, int d) {
	std::cout << a << " " << b << " " << c << " " << d << std::endl;
}

int main() {
	int a = 0, b = 1, c = 2, d = 3;
	int hit, blow;

	print(a, b, c, d);
	std::cin >> hit >> blow;

	if (hit == 4) return 0;

	int h, bl, pre;
	if (hit + blow != 4) {
		while (d < 10) {
			print(a, b, c, d);
			std::cin >> h >> bl;
			if (h == 4) return 0;
			if (h + bl > hit + blow) {
				hit = h;
				blow = bl;
				break;
			}
			if (h + bl < hit + blow) {
				d = pre;
				break;
			}
			pre = d;
			d++;
		}
	}
	if (hit + blow != 4) {
		while (c < 10) {
			if (c == d) {
				c++;
				continue;
			}
			print(a, b, c, d);
			std::cin >> h >> bl;
			if (h == 4) return 0;
			if (h + bl > hit + blow) {
				hit = h;
				blow = bl;
				break;
			}
			if (h + bl < hit + blow) {
				c = pre;
				break;
			}

			pre = c;
			c++;
		}
	}

	if (hit + blow != 4) {
		while (b < 10) {
			if (b == c || b == d) {
				b++;
				continue;
			}
			print(a, b, c, d);
			std::cin >> h >> bl;
			if (h == 4) return 0;
			if (h + bl > hit + blow) {
				hit = h;
				blow = bl;
				break;
			}
			if (h + bl < hit + blow) {
				b = pre;
				break;
			}

			pre = b;
			b++;
		}
	}

	if (hit + blow != 4) {
		while (a < 10) {
			if (a == b || a == c || a == d) {
				a++;
				continue;
			}
			print(a, b, c, d);
			std::cin >> h >> bl;
			if (h == 4) return 0;
			if (h + bl > hit + blow) {
				hit = h;
				blow = bl;
				break;
			}
			if (h + bl < hit + blow) {
				a = pre;
				break;
			}

			pre = a;
			a++;
		}
	}

	std::vector<int> v;
	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	v.push_back(d);

	std::sort(v.begin(), v.end());

	do {
		print(v[0], v[1], v[2], v[3]);
		std::cin >> h >> bl;
		if (h == 4) return 0;
	} while (std::next_permutation(v.begin(), v.end()));

	return 0;
}
0