Skip to content

Instantly share code, notes, and snippets.

@frodo821
Created August 24, 2019 18:10
Show Gist options
  • Select an option

  • Save frodo821/54cf387078899f297e4f2fdd2ce4e5c3 to your computer and use it in GitHub Desktop.

Select an option

Save frodo821/54cf387078899f297e4f2fdd2ce4e5c3 to your computer and use it in GitHub Desktop.
practice B
from sys import stdout as sys
n, q = map(int, input().split())
k = list("abcdefghijklmnopqrstuvwxyz"[:n])
cn = 0
memo = {}
def comp(a, b):
global cn
if a+b in memo:
return memo[a+b]
if b+a in memo:
return not memo[a+b]
if cn >= q:
raise Exception()
cn += 1
print("? %s %s" % (a, b))
sys.flush()
ans = input()
memo[a+b] = ans == ">"
return memo[a+b]
def swap(t, p1, p2):
t[p2], t[p1] = t[p1], t[p2]
def main():
lim = len(k)
try:
for i in range(lim):
flag = True
for c in range(lim - i - 1):
if comp(k[c], k[c + 1]):
swap(k, c, c + 1)
flag = False
if flag:
break
except: pass
print('! '+''.join(k).upper())
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment