import sys
from collections import deque
input=sys.stdin.readline
N,M,T=map(int,input().split())
arr=[deque(map(int,input().split())) for _ in range(N)]
for tc in range(T):
x,d,k=map(int,input().split())
x-=1
d=1 if d==0 else -1
for idx in range(x,N,x+1):
for turn in range(k):
arr[idx].rotate(d)
remove=[]
# 양 옆 확인하기
for r in range(N):
for c in range(-1,M-1):
if arr[r][c]=='x' or arr[r][c+1]=='x': continue
if arr[r][c]==arr[r][c+1]:
remove.extend([(r,c),(r,c+1)])
# 위 아래 확인하기
for c in range(M):
for r in range(N-1):
if arr[r][c] == 'x' or arr[r+1][c] == 'x': continue
if arr[r][c]==arr[r+1][c]:
remove.extend([(r,c),(r+1,c)])
for r,c in set(remove):
arr[r][c]='x' # 값 지우기
total, cnt = 0, 0
for r in range(N):
for c in range(M):
if arr[r][c] != 'x':
total += arr[r][c]
cnt += 1
if len(remove)==0:
if cnt!=0:
avg=total/cnt # 평균 비교해서 값 수정하기
for r in range(N):
for c in range(M):
if arr[r][c]!='x':
if arr[r][c]<avg: arr[r][c]+=1
elif arr[r][c]>avg: arr[r][c]-=1
total=0
for r in range(N):
for c in range(M):
if arr[r][c] != 'x':
total += arr[r][c]
print(total)
https://www.acmicpc.net/problem/17822
17822번: 원판 돌리기
반지름이 1, 2, ..., N인 원판이 크기가 작아지는 순으로 바닥에 놓여있고, 원판의 중심은 모두 같다. 원판의 반지름이 i이면, 그 원판을 i번째 원판이라고 한다. 각각의 원판에는 M개의 정수가 적혀
www.acmicpc.net
'IT > coding study' 카테고리의 다른 글
[acmicpc] 2206. 벽 부수고 이동하기(python) (0) | 2022.10.10 |
---|---|
[acmicpc] 21921. 블로그 (python) (0) | 2022.10.04 |
[acmicpc] 20437. 문자열 게임 2 (python) (0) | 2022.09.22 |
[acmicpc] 1806. 부분합(python) (2) | 2022.09.21 |
[acmicpc] 1987. 알파벳(python) (0) | 2022.09.19 |