| ps | |
|---|---|
| 링크 | acmicpc.net/… |
| 출처 | BOJ |
| 문제 번호 | 2840 |
| 문제명 | 행운의 바퀴 |
| 레벨 | 실버 4 |
| 분류 |
구현 |
| 시간복잡도 | O(n) |
| 인풋사이즈 | n<100 |
| 사용한 언어 | Python |
| 제출기록 | 30840KB / 72ms |
| 최고기록 | 56ms |
| 해결날짜 | 2022/04/26 |
| 태그 | |
"""Solution code for "BOJ 2840. 행운의 바퀴".
- Problem link: https://www.acmicpc.net/problem/2840
- Solution link: http://www.teferi.net/ps/problems/boj/2840
"""
def main():
N, K = [int(x) for x in input().split()]
turns = [input().split() for _ in range(K)]
pos = 0
wheel = ['?'] * N
for S, ch in reversed(turns):
if wheel[pos] not in (ch, '?'):
answer = '!'
break
wheel[pos] = ch
pos = (pos + int(S)) % N
else:
alphabets = [x for x in wheel if x != '?']
answer = (''.join(wheel)
if len(set(alphabets)) == len(alphabets) else '!')
print(answer)
if __name__ == '__main__':
main()