Search
Duplicate
๐Ÿฅ‡

AC

์ฃผ์ฐจ
20
๋ฌธ์ œ๋ฒˆํ˜ธ
5430
์–ธ์–ด
Python
ํ‹ฐ์–ด
๊ณจ๋“œ
์œ ํ˜•
๊ตฌํ˜„
nj_Blog
X
nj_์ƒํƒœ
ํ‘ธ๋Š” ์ค‘
์ดํ•ด๋„
ํ’€์ด
์‚ฌ๋žŒ
์ดํ•ด๋„ 2
13 more properties

๋ฌธ์ œ๋งํฌ

https://www.acmicpc.net/problem/5430

์ฝ”๋“œ ์ œ์ถœ ๊ธฐ๋ก (๋ฉ”๋ชจ๋ฆฌ ๋ฐ ์‹œ๊ฐ„)

์ œ์ถœ ๋‚ ์งœ

@5/20/2021

๋ฉ”๋ชจ๋ฆฌ

KB

์‹œ๊ฐ„

ms

๋ฌธ์ œํ’€์ด

start, end ๋ณ€์ˆ˜๋กœ ๋ฐฐ์—ด์˜ ์ฒ˜์Œ๊ณผ ๋์„ ์ €์žฅ!
R ๋ช…๋ น์–ด์ผ๋•Œ โ†’ start ์™€ end๋ฅผ ์„œ๋กœ ๋ฐ”๊ฟ”์คŒ
D ๋ช…๋ น์–ด์ผ๋•Œ โ†’ start < end๋ผ๋ฉด start += 1
start > end ๋ผ๋ฉด start -= 1
๊ฒฐ๊ณผ ์ถœ๋ ฅ โ†’ start < end๋ผ๋ฉด arr[start : end + 1] ์ถœ๋ ฅ
start > end ๋ผ๋ฉด arr[end : start + 1].reverse() ์ถœ๋ ฅ

Code

์‹œ๊ฐ„์ดˆ๊ณผ..
T = int(input()) for _ in range(T): cmd = str(input()) arr_len = int(input()) arr_ = str(input()) arr_ = arr_[1:-1].split(',') arr = [] flag = 0 for i in range(arr_len): arr.append(int(arr_[i])) location = 0 for i in range(len(cmd)): if cmd[i] == 'R': location = -1 if (location == 0) else (0) elif cmd[i] == 'D': if len(arr) == 0: flag = 1 break arr = arr[1:] if (location == 0) else (arr[0:-1]) if location == -1: arr.reverse() if flag == 1: print("error") else: print(arr) arr.clear() arr_.clear()
Python
๋ณต์‚ฌ
์‹œ๊ฐ„์ดˆ๊ณผ..
T = int(input()) for _ in range(T): cmd = str(input()) arr_len = int(input()) arr_ = str(input()) arr_ = arr_[1:-1].split(',') arr = [] flag = 0 for i in range(arr_len): arr.append(int(arr_[i])) start = 0 end = arr_len -1 for i in range(len(cmd)): if cmd[i] == 'R': start, end = end, start elif cmd[i] == 'D': if len(arr) == 0: flag = 1 break if start < end: start += 1 elif start > end: start -= 1 else: flag = 1 break if flag == 1: print("error") else: if start > end: arr_tmp = arr[end : start + 1] arr_tmp.reverse() print(arr_tmp) elif start < end: print(arr[start : end + 1]) else: print("[]") arr.clear() arr_.clear()
C
๋ณต์‚ฌ

์ฐธ๊ณ