import numpy as np
def main():
import sys
input = sys.stdin.read().split()
idx = 0
R = int(input[idx]); idx +=1
C = int(input[idx]); idx +=1
M = int(input[idx]); idx +=1
grid = []
for _ in range(R):
line = input[idx].strip()
grid.append( list(line) )
idx +=1
commands = input[idx].strip()
# Create water mask
water_mask = np.zeros((R, C), dtype=bool)
for i in range(R):
for j in range(C):
if grid[i][j] == '.':
water_mask[i][j] = True
prev_dp = water_mask.copy()
for cmd in commands:
if cmd == 'N':
shifted = np.roll(prev_dp, -1, axis=0)
shifted[-1, :] = False
elif cmd == 'S':
shifted = np.roll(prev_dp, 1, axis=0)
shifted[0, :] = False
elif cmd == 'E':
shifted = np.roll(prev_dp, -1, axis=1)
shifted[:, -1] = False
elif cmd == 'W':
shifted = np.roll(prev_dp, 1, axis=1)
shifted[:, 0] = False
elif cmd == '?':
# North shift
shifted_n = np.roll(prev_dp, -1, axis=0)
shifted_n[-1, :] = False
# South shift
shifted_s = np.roll(prev_dp, 1, axis=0)
shifted_s[0, :] = False
# East shift
shifted_e = np.roll(prev_dp, -1, axis=1)
shifted_e[:, -1] = False
# West shift
shifted_w = np.roll(prev_dp, 1, axis=1)
shifted_w[:, 0] = False
shifted = shifted_n | shifted_s | shifted_e | shifted_w
else:
shifted = np.zeros_like(prev_dp)
# Apply water mask
current_dp = shifted & water_mask
prev_dp = current_dp.copy()
print(np.sum(prev_dp))
if __name__ == "__main__":
main()
컴파일 시 표준 출력 (stdout) 메시지
Compiling 'nautilus.py'...
=======
adding: __main__.pyc (deflated 42%)
=======
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |