제출 #1136276

#제출 시각아이디문제언어결과실행 시간메모리
1136276hwcho98Play Onwards (FXCUP2_onward)Pypy 3
1 / 1
188 ms51184 KiB
import sys from collections import deque input = sys.stdin.readline n,k = map(int,input().split()) bd = [[] for _ in range(n)] lst = [] for _ in range(n): cur = input().rstrip() lst.append(set([cur[i-k:i] for i in range(k,len(cur)+1)])) for i,c in enumerate(lst): for j,s in enumerate(lst[i+1:],i+1): if c.intersection(s): bd[i].append(j) bd[j].append(i) ans = [0]*n vis = [0]*n for i in range(n): if ans[i]: continue ans[i] = vis[i] = 1 q = deque([i]) while q: cur = q.popleft() pos = 3-ans[cur] for nxt in bd[cur]: if ans[nxt] == pos: continue elif ans[nxt]: exit(print('No')) ans[nxt] = pos q.append(nxt) if sum(ans) == n: ans[-1] = 2 print('Yes') print(*ans,sep='\n')

컴파일 시 표준 출력 (stdout) 메시지

Compiling 'onward.py'...

=======
  adding: __main__.pyc (deflated 35%)

=======
#Verdict Execution timeMemoryGrader output
Fetching results...