結果

問題 No.355 数当てゲーム(2)
ユーザー bal4ubal4u
提出日時 2019-06-23 09:02:21
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,197 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 29,372 KB
実行使用メモリ 24,420 KB
平均クエリ数 21.48
最終ジャッジ日時 2023-09-24 02:15:42
合計ジャッジ時間 4,400 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
24,264 KB
testcase_01 AC 24 ms
23,520 KB
testcase_02 AC 24 ms
24,252 KB
testcase_03 AC 25 ms
24,060 KB
testcase_04 AC 24 ms
23,412 KB
testcase_05 AC 26 ms
23,784 KB
testcase_06 AC 25 ms
23,988 KB
testcase_07 AC 25 ms
24,084 KB
testcase_08 AC 24 ms
23,376 KB
testcase_09 AC 25 ms
23,604 KB
testcase_10 AC 24 ms
23,652 KB
testcase_11 AC 23 ms
23,856 KB
testcase_12 AC 23 ms
23,388 KB
testcase_13 AC 24 ms
23,520 KB
testcase_14 AC 24 ms
23,856 KB
testcase_15 AC 24 ms
23,388 KB
testcase_16 AC 24 ms
23,364 KB
testcase_17 AC 24 ms
24,288 KB
testcase_18 AC 24 ms
24,060 KB
testcase_19 AC 24 ms
24,096 KB
testcase_20 AC 24 ms
23,988 KB
testcase_21 AC 24 ms
24,012 KB
testcase_22 AC 23 ms
24,360 KB
testcase_23 AC 23 ms
23,628 KB
testcase_24 AC 23 ms
24,420 KB
testcase_25 AC 23 ms
23,448 KB
testcase_26 AC 24 ms
23,448 KB
testcase_27 AC 23 ms
23,796 KB
testcase_28 AC 24 ms
24,072 KB
testcase_29 AC 22 ms
23,988 KB
testcase_30 AC 24 ms
24,000 KB
testcase_31 AC 22 ms
23,388 KB
testcase_32 AC 25 ms
23,208 KB
testcase_33 AC 24 ms
24,072 KB
testcase_34 AC 24 ms
23,376 KB
testcase_35 AC 22 ms
23,664 KB
testcase_36 AC 25 ms
23,616 KB
testcase_37 AC 25 ms
24,312 KB
testcase_38 AC 25 ms
23,880 KB
testcase_39 AC 24 ms
24,420 KB
testcase_40 AC 25 ms
23,364 KB
testcase_41 AC 25 ms
23,856 KB
testcase_42 AC 24 ms
23,988 KB
testcase_43 AC 24 ms
24,300 KB
testcase_44 AC 26 ms
23,580 KB
testcase_45 AC 23 ms
23,520 KB
testcase_46 AC 24 ms
24,000 KB
testcase_47 AC 24 ms
23,676 KB
testcase_48 AC 24 ms
23,700 KB
testcase_49 AC 24 ms
23,580 KB
testcase_50 AC 25 ms
23,436 KB
testcase_51 AC 25 ms
23,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder: No.355 数当てゲーム(2)
// 2019.6.23 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define pc(c) putchar(c)
char a[15], f[10];
char ans[15];
int  k;

int ask(char *x) {
	int i, d0, d1;
	pc(x[0]); for (i = 1; i < 4; i++) pc(' '), pc(x[i]);
	pc('\n'), fflush(stdout);
	scanf("%d%d", &d0, &d1);
	if (d0 == 4) exit(0);
	return d0 + d1;
}

void rec(int id, char *x) {
	int i;
	if (id == 4) ask(x);
	else {
		for (i = 0; i < 4; i++) if (!f[i]) {
			f[i] = 1, x[id] = a[i];
			rec(id+1, x);
			f[i] = 0;
		}
	}
}

void check(char *x) {
	int i, j, c, t0, t, f;
	char eq[5];
	
	t0 = ask(x);
	if (t0 == 4) {
		for (i = 0; i < 4; i++) ans[x[i]&0xf] = 1;
		k = 4;
		return;
	}
	f = 0, j = 0;
	for (i = 0; i < 4; i++) {
		c = x[i], x[i] = x[4];
		t = ask(x);
		if (t < t0) k++, ans[c & 0xf] = 1;
		else if (t > t0) ans[x[4] & 0xf] = 1, f = 1;
		else {
			if (f) ans[c & 0xf] = 1;
			else eq[j++] = c;
		}
		x[i] = c;
	}
	if (f) for (i = 0; i < j; i++) ans[eq[i] & 0xf] = 1, k++;
}

int main()
{
	int i, j;
	
	strcpy(a, "01234"), check(a);
	if (k < 4) strcpy(a, "56789"), check(a);
	j = 0; for (i = 0; i < 10; i++) if (ans[i]) a[j++] = i + '0';
	rec(0, ans);
	return 0;
}
0