結果

問題 No.355 数当てゲーム(2)
ユーザー bal4ubal4u
提出日時 2019-06-23 08:58:04
言語 C
(gcc 12.3.0)
結果
RE  
実行時間 -
コード長 1,197 bytes
コンパイル時間 393 ms
コンパイル使用メモリ 29,276 KB
実行使用メモリ 24,480 KB
平均クエリ数 21.48
最終ジャッジ日時 2023-09-23 17:19:48
合計ジャッジ時間 4,345 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
権限があれば一括ダウンロードができます

ソースコード

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(1);
	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