結果

問題 No.355 数当てゲーム(2)
ユーザー cielciel
提出日時 2016-04-01 23:29:39
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 1,910 ms / 2,000 ms
コード長 944 bytes
コンパイル時間 564 ms
コンパイル使用メモリ 78,160 KB
実行使用メモリ 117,252 KB
平均クエリ数 5.12
最終ジャッジ日時 2023-09-23 09:44:07
合計ジャッジ時間 62,925 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,826 ms
117,116 KB
testcase_01 AC 482 ms
116,284 KB
testcase_02 AC 421 ms
115,244 KB
testcase_03 AC 680 ms
115,784 KB
testcase_04 AC 692 ms
115,652 KB
testcase_05 AC 394 ms
114,792 KB
testcase_06 AC 495 ms
116,604 KB
testcase_07 AC 696 ms
117,120 KB
testcase_08 AC 670 ms
115,424 KB
testcase_09 AC 708 ms
116,168 KB
testcase_10 AC 466 ms
116,284 KB
testcase_11 AC 1,816 ms
116,344 KB
testcase_12 AC 369 ms
115,220 KB
testcase_13 AC 361 ms
115,868 KB
testcase_14 AC 1,447 ms
116,184 KB
testcase_15 AC 319 ms
114,952 KB
testcase_16 AC 376 ms
115,572 KB
testcase_17 AC 1,473 ms
116,716 KB
testcase_18 AC 1,472 ms
115,704 KB
testcase_19 AC 754 ms
115,636 KB
testcase_20 AC 421 ms
115,076 KB
testcase_21 AC 1,509 ms
116,124 KB
testcase_22 AC 367 ms
115,640 KB
testcase_23 AC 689 ms
115,620 KB
testcase_24 AC 485 ms
115,968 KB
testcase_25 AC 697 ms
116,232 KB
testcase_26 AC 1,480 ms
116,496 KB
testcase_27 AC 1,455 ms
117,168 KB
testcase_28 AC 727 ms
116,696 KB
testcase_29 AC 398 ms
115,408 KB
testcase_30 AC 1,910 ms
115,868 KB
testcase_31 AC 1,484 ms
116,028 KB
testcase_32 AC 1,597 ms
117,252 KB
testcase_33 AC 454 ms
115,168 KB
testcase_34 AC 1,537 ms
116,820 KB
testcase_35 AC 452 ms
114,508 KB
testcase_36 AC 496 ms
115,772 KB
testcase_37 AC 1,822 ms
116,516 KB
testcase_38 AC 1,561 ms
116,648 KB
testcase_39 AC 1,503 ms
117,244 KB
testcase_40 AC 420 ms
116,148 KB
testcase_41 AC 353 ms
114,836 KB
testcase_42 AC 1,907 ms
117,044 KB
testcase_43 AC 1,812 ms
116,648 KB
testcase_44 AC 374 ms
115,412 KB
testcase_45 AC 327 ms
115,788 KB
testcase_46 AC 698 ms
116,992 KB
testcase_47 AC 311 ms
115,212 KB
testcase_48 AC 701 ms
115,692 KB
testcase_49 AC 380 ms
115,560 KB
testcase_50 AC 1,566 ms
116,488 KB
testcase_51 AC 1,461 ms
116,848 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