답안 #133466

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
133466 2019-07-20T20:40:03 Z tnbs10 ZigZag (COCI17_zigzag) Python 3
80 / 80
896 ms 14924 KB
k, n = map(int, input().split())
a = [[] for i in range(26)]
for i in range(k):
    x = input()
    a[ord(x[0]) - 97].append(x)
for i in range(26):
    a[i].sort()
    # print(a[i])
# napraviti [[adam, az], [ba, bd]] i onda samo šaltati
# kad se uzme jednom a da se uzme adam i baci ga se na kraj
# [adam, az] -> [az, adam]
#
# uvijek uzeti prvu u listi tog slova
r = [input() for i in range(n)]
for i in r:
    print(a[ord(i) - 97][0])
    a[ord(i) - 97].append(a[ord(i) - 97].pop(0))
    
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 3520 KB Output is correct
2 Correct 26 ms 3300 KB Output is correct
3 Correct 27 ms 3316 KB Output is correct
4 Correct 27 ms 3392 KB Output is correct
5 Correct 27 ms 3392 KB Output is correct
6 Correct 27 ms 3392 KB Output is correct
7 Correct 894 ms 14856 KB Output is correct
8 Correct 893 ms 14920 KB Output is correct
9 Correct 896 ms 14924 KB Output is correct
10 Correct 886 ms 14876 KB Output is correct