Muscardinus
낚시왕 본문
728x90
#include <iostream>
using namespace std;
struct CELL {
int s, d, z;
};
CELL map[2][101][101];
int r, c, m;
int cur = 0;
int fishing(int cur, int pos) {
int size = 0;
for (int y = 0; y < r; y++) {
if (map[cur][y][pos].z) {
size = map[cur][y][pos].z;
map[cur][y][pos].s = 0;
map[cur][y][pos].d = 0;
map[cur][y][pos].z = 0;
break;
}
}
return size;
}
void move(int cur) {
int next = (cur + 1) % 2;
for (int y = 0; y < r; y++) {
for (int x = 0; x < c; x++) {
map[next][y][x].s = 0;
map[next][y][x].d = 0;
map[next][y][x].z = 0;
}
}
for (int y = 0; y < r; y++) {
for (int x = 0; x < c; x++) {
if (map[cur][y][x].z) {
if (map[cur][y][x].d == 1) {
int ny = ((r - 1) * 2 - y) + map[cur][y][x].s;
ny = (ny % ((r - 1) * 2));
int nd = 2;
if (ny >= (r - 1)) {
ny = ((r - 1) * 2) - ny;
nd = 1;
}
if (map[next][ny][x].z < map[cur][y][x].z) {
map[next][ny][x].s = map[cur][y][x].s;
map[next][ny][x].d = nd;
map[next][ny][x].z = map[cur][y][x].z;
}
}
else if (map[cur][y][x].d == 2) {
int ny = y + map[cur][y][x].s;
ny = (ny % ((r - 1) * 2));
int nd = 2;
if (ny >= (r - 1)) {
ny = ((r - 1) * 2) - ny;
nd = 1;
}
if (map[next][ny][x].z < map[cur][y][x].z) {
map[next][ny][x].s = map[cur][y][x].s;
map[next][ny][x].d = nd;
map[next][ny][x].z = map[cur][y][x].z;
}
}
else if (map[cur][y][x].d == 3) {
int nx = x + map[cur][y][x].s;
nx = (nx % ((c - 1) * 2));
int nd = 3;
if (nx >= (c - 1)) {
nx = ((c - 1) * 2) - nx;
nd = 4;
}
if (map[next][y][nx].z < map[cur][y][x].z) {
map[next][y][nx].s = map[cur][y][x].s;
map[next][y][nx].d = nd;
map[next][y][nx].z = map[cur][y][x].z;
}
}
else {
int nx = ((c - 1) * 2 - x) + map[cur][y][x].s;
nx = (nx % ((c - 1) * 2));
int nd = 3;
if (nx >= c - 1) {
nx = (c - 1) * 2 - nx;
nd = 4;
}
if (map[next][y][nx].z < map[cur][y][x].z) {
map[next][y][nx].s = map[cur][y][x].s;
map[next][y][nx].d = nd;
map[next][y][nx].z = map[cur][y][x].z;
}
}
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin >> r >> c >> m;
int answer = 0;
int y, x;
for (int i = 0; i < m; i++) {
cin >> y >> x;
y--; x--;
cin >> map[cur][y][x].s >> map[cur][y][x].d >> map[cur][y][x].z;
}
for (int pos = 0; pos < c; pos++) {
answer += fishing(cur, pos);
move(cur);
cur = (cur + 1) % 2;
}
cout << answer << "\n";
return 0;
}
728x90
Comments