結果
| 問題 |
No.2768 Password Crack
|
| コンテスト | |
| ユーザー |
イルカ
|
| 提出日時 | 2024-06-10 17:56:24 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,171 bytes |
| コンパイル時間 | 785 ms |
| コンパイル使用メモリ | 82,456 KB |
| 実行使用メモリ | 95,188 KB |
| 平均クエリ数 | 885.40 |
| 最終ジャッジ日時 | 2025-01-02 12:27:19 |
| 合計ジャッジ時間 | 8,421 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 RE * 9 |
ソースコード
# 先頭から長さ4の部分文字列を確定させることを考える
# 他の部分は固定して、先頭だけaaaaからzzzzまで26通り試すことで先頭4文字に含まれる英子文字がわかる(順番はまだわからない)
# ↑でわかった英子文字でつくれる候補を全通り(4種なら4!、3種なら3×(4!/2)、2種なら2×(4!/3!)+2×(4!/2!2!)、1種なら1)調べれば位置もわかる
# これを末尾まで繰り返すことで最大でも(26+36)*(100/4)=1300クエリでできそう
import collections
import itertools
# テスト用関数
def count_match(s1, s2="hffhhwuuorfbwuobfeqpifpefqnp"):
cnt = 0
for i in range(len(s1)):
if s1[i]==s2[i]:
cnt += 1
return cnt
N = int(input())
abc = [chr(ord("a")+i) for i in range(26)]
s = "x"*N
for i in range((N+3)//4):
if N%4!=0 and i==(N+3)//4-1:
chnum = N%4
else:
chnum = 4
r1 = {}
for ch in abc:
s = s[:4*i] + ch*chnum + s[4*(i+1):]
print("? "+s)
r1[ch] = int(input())
#r1[ch] = count_match(s)
matched = collections.Counter(r1.values()).most_common()
cands = []
for c in matched[1:]:
for k, v in r1.items():
if c[0]==v:
cands.append(k)
if len(cands)==4:
perm = ["".join(p) for p in list(itertools.permutations(cands))]
elif len(cands)==3:
perm = []
for c in cands:
perm += list(set(["".join(p) for p in list(itertools.permutations(list(cands)+[c,]))]))
elif len(cands)==2:
perm = []
for c in cands:
perm += list(set(["".join(p) for p in list(itertools.permutations(list(cands)+[c,c,]))]))
perm += list(set(["".join(p) for p in list(itertools.permutations(list(cands)+list(cands)))]))
else:
perm = [cands[0]*4]
ans = ""
max_match = 0
for p in perm:
print("? "+s[:4*i] + p + s[4*(i+1):])
matched = int(input())
#matched = count_match(s[:4*i] + p + s[4*(i+1):])
if matched > max_match:
ans = p
max_match = matched
s = s[:4*i] + ans + s[4*(i+1):]
print("! "+s)
イルカ