結果

問題 No.355 数当てゲーム(2)
ユーザー cielciel
提出日時 2016-04-01 23:29:42
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 1,912 ms / 2,000 ms
コード長 944 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 77,728 KB
実行使用メモリ 117,612 KB
平均クエリ数 5.38
最終ジャッジ日時 2023-09-23 09:45:29
合計ジャッジ時間 55,199 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,495 ms
116,228 KB
testcase_01 AC 377 ms
115,160 KB
testcase_02 AC 469 ms
115,748 KB
testcase_03 AC 313 ms
115,376 KB
testcase_04 AC 1,491 ms
117,340 KB
testcase_05 AC 319 ms
115,192 KB
testcase_06 AC 1,850 ms
117,308 KB
testcase_07 AC 1,912 ms
117,180 KB
testcase_08 AC 426 ms
115,404 KB
testcase_09 AC 314 ms
115,132 KB
testcase_10 AC 1,438 ms
116,328 KB
testcase_11 AC 325 ms
115,444 KB
testcase_12 AC 1,533 ms
117,396 KB
testcase_13 AC 677 ms
115,060 KB
testcase_14 AC 1,466 ms
116,048 KB
testcase_15 AC 326 ms
115,300 KB
testcase_16 AC 462 ms
115,028 KB
testcase_17 AC 458 ms
116,220 KB
testcase_18 AC 1,762 ms
115,924 KB
testcase_19 AC 1,837 ms
117,612 KB
testcase_20 AC 347 ms
115,348 KB
testcase_21 AC 429 ms
114,764 KB
testcase_22 AC 1,386 ms
116,012 KB
testcase_23 AC 476 ms
115,308 KB
testcase_24 AC 421 ms
116,120 KB
testcase_25 AC 669 ms
115,908 KB
testcase_26 AC 374 ms
115,312 KB
testcase_27 AC 360 ms
115,232 KB
testcase_28 AC 723 ms
116,424 KB
testcase_29 AC 296 ms
115,100 KB
testcase_30 AC 1,449 ms
116,616 KB
testcase_31 AC 1,561 ms
115,900 KB
testcase_32 AC 436 ms
114,928 KB
testcase_33 AC 433 ms
115,076 KB
testcase_34 AC 1,462 ms
116,396 KB
testcase_35 AC 633 ms
115,564 KB
testcase_36 AC 275 ms
114,100 KB
testcase_37 AC 498 ms
115,672 KB
testcase_38 AC 676 ms
115,956 KB
testcase_39 AC 472 ms
116,560 KB
testcase_40 AC 734 ms
117,556 KB
testcase_41 AC 1,478 ms
117,460 KB
testcase_42 AC 259 ms
114,844 KB
testcase_43 AC 464 ms
116,576 KB
testcase_44 AC 438 ms
115,592 KB
testcase_45 AC 647 ms
116,856 KB
testcase_46 AC 282 ms
115,084 KB
testcase_47 AC 490 ms
115,672 KB
testcase_48 AC 513 ms
115,692 KB
testcase_49 AC 359 ms
115,280 KB
testcase_50 AC 465 ms
116,312 KB
testcase_51 AC 1,471 ms
116,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
from collections import Counter
import itertools,random

digits=4

def hit_and_blow(a,b):
	hit=sum(a[i]==b[i] for i in range(digits))
	blow=len(a)+len(b)-len(set(iter(a+b)))
	return (hit,blow-hit)

def minimax(e):
	h={}
	for f in lst:
		x=hit_and_blow(e,f)
		if x not in h: h[x]=0
		h[x]+=1
	return (max(h.values()),e)

def genlist():
	return list(''.join(e) for e in itertools.permutations(iter('0123456789'),digits))

def checkio(last,hit,blow):
	global lst
	if last is None:
		lst=genlist()
		return random.choice(lst)
	for i in range(len(lst)-1,-1,-1):
		if hit_and_blow(lst[i],last)!=(hit,blow): lst.pop(i)
	return min(minimax(e) for e in lst)[1]
	#return random.choice(lst)

if __name__ == '__main__':
	import sys
	if sys.version_info[0]>=3: raw_input=input
	q=None
	hit=blow=0
	while True:
		s=checkio(q,hit,blow)
		print(' '.join(s))
		sys.stdout.flush()
		hit,blow=map(int,raw_input().split())
		if hit==4:break
		q=s
0