結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,520 KB
testcase_01 AC 23 ms
23,340 KB
testcase_02 AC 23 ms
24,204 KB
testcase_03 AC 23 ms
24,000 KB
testcase_04 AC 22 ms
24,372 KB
testcase_05 AC 22 ms
24,420 KB
testcase_06 AC 23 ms
23,640 KB
testcase_07 AC 22 ms
24,288 KB
testcase_08 AC 22 ms
23,364 KB
testcase_09 AC 22 ms
24,252 KB
testcase_10 AC 22 ms
23,952 KB
testcase_11 AC 22 ms
23,376 KB
testcase_12 AC 23 ms
23,388 KB
testcase_13 AC 24 ms
23,364 KB
testcase_14 AC 22 ms
24,000 KB
testcase_15 AC 22 ms
23,604 KB
testcase_16 AC 22 ms
24,264 KB
testcase_17 AC 22 ms
23,520 KB
testcase_18 AC 23 ms
23,940 KB
testcase_19 AC 23 ms
24,000 KB
testcase_20 AC 25 ms
23,376 KB
testcase_21 AC 23 ms
23,364 KB
testcase_22 AC 23 ms
23,400 KB
testcase_23 AC 23 ms
24,396 KB
testcase_24 AC 25 ms
23,784 KB
testcase_25 AC 22 ms
24,360 KB
testcase_26 AC 23 ms
23,700 KB
testcase_27 AC 22 ms
23,808 KB
testcase_28 AC 23 ms
23,508 KB
testcase_29 AC 22 ms
23,520 KB
testcase_30 AC 23 ms
23,652 KB
testcase_31 AC 22 ms
23,940 KB
testcase_32 AC 23 ms
23,508 KB
testcase_33 AC 22 ms
24,312 KB
testcase_34 AC 23 ms
23,808 KB
testcase_35 AC 23 ms
24,348 KB
testcase_36 AC 22 ms
23,664 KB
testcase_37 AC 24 ms
24,012 KB
testcase_38 AC 23 ms
23,508 KB
testcase_39 AC 24 ms
24,000 KB
testcase_40 AC 23 ms
24,204 KB
testcase_41 AC 22 ms
24,360 KB
testcase_42 AC 23 ms
23,532 KB
testcase_43 AC 23 ms
24,240 KB
testcase_44 AC 25 ms
24,240 KB
testcase_45 AC 23 ms
23,364 KB
testcase_46 AC 22 ms
23,532 KB
testcase_47 AC 22 ms
24,276 KB
testcase_48 AC 22 ms
23,796 KB
testcase_49 AC 22 ms
23,520 KB
testcase_50 AC 23 ms
23,520 KB
testcase_51 AC 22 ms
24,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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

int ask(char *x) {
	int i;
	pc(x[0]); for (i = 1; i < 4; i++) pc(' '), pc(x[i]);
	pc('\n'), fflush(stdout);
	if ((i = gc() & 0xf) == 4) exit(0);
	gc(), i += gc() & 0xf, gc();
	return i;
}

void rec(int id) {
	int i;
	if (id == 4) ask(ans);
	else {
		for (i = 0; i < 4; i++) if (!f[i]) {
			f[i] = 1, ans[id] = a[i];
			rec(id + 1);
			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);
	return 0;
}
0