Submission #88415

#TimeUsernameProblemLanguageResultExecution timeMemory
88415KoscheiCezar (COCI16_cezar)Cpython 3
10 / 100
32 ms3736 KiB
alphabet = 'abcdefghijklmnopqrstuvwxyz' def rule_maker(r1, r2): for i, j in zip(r1, r2): if i != j: sought = (i, j); break else: if len(r1) <= len(r2): sought = 1 else: sought = 0 return sought def visit(graph, firth, temp, perm, final, unmarked): global t if temp[ord(firth)-97]: t = 1 elif not(perm[ord(firth)-97]): temp[ord(firth)-97] = 1 for forth in graph[firth]: m = visit(graph, forth, temp, perm, final, unmarked) unmarked.discard(firth) perm[ord(firth)-97] = 1 temp[ord(firth)-97] = 0 final.append(firth) n = int(input()) words = [input() for i in range(n)] neu = [int(i) for i in input().split(" ")] final_words = [words[i-1] for i in neu] diktafon = {} for i in range(97, 123): diktafon[chr(i)] = [] f = 1 rules = 0 for i, w0 in enumerate(final_words): for w1 in final_words[(i+1):]: s = rule_maker(w0, w1) if s == 0: f = 0; break elif s != 1: diktafon[s[0]].append(s[1]) rules = 1 if f == 0: print("NE") elif not(rules): print("DA"); print(alphabet) else: t = 0 temp = [0]*26; perm = [0]*26 final = [] unmarked = set(chr(i) for i in range(97, 123)) while unmarked: s = unmarked.pop() visit(diktafon, s, temp, perm, final, unmarked) if t: print("NE"); break else: final.reverse() print("DA") makn = set() sa = set(alphabet) k = [0]*26 for i, l in enumerate(final): k[ord(l)-97] = alphabet[i] sa -= {alphabet[i]} for i in range(26): if not(k[i]): k[i] = sa.pop() print("".join(k))
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...