작성
·
128
0
오래 걸렸지만, 혼자 풀어서 정답처리가 되었는데,
모듈러 연산으로 moveShark를 한것이 아니고, 한 칸 한 칸 이동하는 방식이었습니다.
운 좋게 통과한 것 같네요.
#include <bits/stdc++.h>
using namespace std;
int R, C, M;
vector<vector<tuple<int, int, int>>> B;
void moveShark(vector<vector<tuple<int, int, int>>>& B){
vector<vector<tuple<int, int, int>>> tempB = B;
vector<vector<int>> visited(R+1, vector<int>(C+1,0));
for(int i = 1 ; i <= R; ++i){
for(int j = 1; j <= C; ++j){
int speed = get<0>(B[i][j]);
int delta = get<1>(B[i][j]); // d:up(1), d:down(2), d:right(3), d:left(4)
int size = get<2>(B[i][j]);
if (size != 0){
if (visited[i][j] == 0) tempB[i][j] = {0,0,0};
if (delta == 1){
int s = i;
int mov = -1;
int sd = speed;
while(sd > 0){
if ((s+mov >= 1) && (s+mov <= R)) s = s+mov;
else{ s = s-mov, mov *= -1;}
if ((s == 1) || (s == R)) mov *= -1;
sd--;
}
if (visited[s][j] == 0 ||get<2>(tempB[s][j]) < size){
if (mov == -1) tempB[s][j] = {speed, 1, size};
else tempB[s][j] = {speed, 2, size};
visited[s][j] = 1;
}
}
else if (delta == 2){
int s = i;
int mov = 1;
int sd = speed;
while(sd>0){
if ((s+mov >= 1) && (s+mov <= R)) s = s+mov;
else s = s-mov, mov *= -1;
if ((s == 1) || (s == R)) mov *= -1;
sd--;
}
if (visited[s][j] == 0 || get<2>(tempB[s][j]) < size){
if (mov == -1) tempB[s][j] = {speed, 1, size};
else tempB[s][j] = {speed, 2, size};
visited[s][j] = 1;
}
}
else if (delta == 3){
int s = j;
int mov = 1;
int sd = speed;
while(sd>0){
if ((s+mov >= 1) && (s+mov <= C)) s = s+mov;
else s = s-mov, mov *= -1;
if ((s == 1) || (s == C)) mov *= -1;
sd--;
}
if (visited[i][s] == 0 || get<2>(tempB[i][s]) < size){
if (mov == -1) tempB[i][s] = {speed, 4, size};
else tempB[i][s] = {speed, 3, size};
visited[i][s] = 1;
}
}
else if (delta == 4){
int s = j;
int mov = -1;
int sd = speed;
while(sd>0){
if ((s+mov >= 1) && (s+mov <= C)) s = s+mov;
else s = s-mov, mov *= -1;
if ((s == 1) || (s == C)) mov *= -1;
sd--;
}
if (visited[i][s] == 0 || get<2>(tempB[i][s]) < size){
if (mov == -1) tempB[i][s] = {speed, 4, size};
else tempB[i][s] = {speed, 3, size};
visited[i][s] = 1;
}
}
}
}
}
B = tempB;
}
int fishShark(vector<vector<tuple<int, int, int>>>& B, int c){
int size = 0;
for(int i = 1; i <= R; ++i){
size = get<2>(B[i][c]);
if (size != 0){
B[i][c] = {0,0,0};
break;
}
}
return size;
}
void debug(){
for(int i = 1; i <= R ; ++i){
for(int j = 1; j <= C ; ++j){
cout << get<0>(B[i][j]) << "," << get<1>(B[i][j]) << "," << get<2>(B[i][j]) << "\t" ;
}
cout << endl;
}
}
int main(){
cin >> R >> C >> M;
B = vector<vector<tuple<int, int, int>>>(R+1, vector<tuple<int, int, int>>(C+1, {0,0,0}));
int r, c, s, d, z;
for(int i =0 ; i < M ; ++i){
cin >> r >> c >> s >> d >> z;
B[r][c] = {s, d, z};
}
long long ret = 0;
for(int i = 1; i <= C ; ++i){
// cout << i << "th" << endl;
// debug();
ret+=fishShark(B, i);
// cout << "SZ: " << ret << endl;
moveShark(B);
}
cout << ret;
return 0;
}