voidmoveShark(int idx, int end){ int period = 2 * end; int move = sharks[idx].speed % period; for (int i = 0; i < move; ++i) { if (sharks[idx].direction <= 2) { // 상하 if ((sharks[idx].row == end && sharks[idx].direction == 2) || (sharks[idx].row == 0 && sharks[idx].direction == 1)) { changeDirection(idx); } sharks[idx].row += dx[sharks[idx].direction - 1]; } else { // 우좌 if ((sharks[idx].col == end && sharks[idx].direction == 3) || (sharks[idx].col == 0 && sharks[idx].direction == 4)) { changeDirection(idx); } sharks[idx].col += dy[sharks[idx].direction-1]; } } }
voidupdateMap(){ for (int i = 0; i < r; ++i) { for (int j = 0; j < c; ++j) { map[i][j][0] = 0; } } for (int i = 0; i < m; ++i) { if (sharks[i].death) continue; int r = sharks[i].row; int c = sharks[i].col; if (map[r][c][0] != 0) { // 해당 위치에 상어가 있다면 if (sharks[i].size > map[r][c][0]) { sharks[map[r][c][1]].death = true; map[r][c][0] = sharks[i].size; map[r][c][1] = i; } else { sharks[i].death = true; } } else { // 해당 위치에 상어가 없을 때 map[r][c][0] = sharks[i].size; map[r][c][1] = i; } } }
intmain(){ scanf("%d %d %d", &r, &c, &m); int row, col; for (int i = 0; i < m; ++i) { scanf("%d", &row); sharks[idx].row = row - 1; scanf("%d", &col); sharks[idx].col = col - 1; scanf("%d", &sharks[idx].speed); scanf("%d", &sharks[idx].direction); scanf("%d", &sharks[idx++].size); } updateMap(); /*for (int i = 0; i < m; ++i) { // 입력 확인 printf("%d %d %d %d %d\n", sharks[i].row, sharks[i].col, sharks[i].speed, sharks[i].direction, sharks[i].size); }*/ for (int i = 0; i < c; ++i) { catchShark(i); for (int j = 0; j < m; ++j) { if (sharks[j].death) continue; if (sharks[j].direction <= 2) { moveShark(j, r-1); } else { moveShark(j, c-1); } } updateMap(); } printf("%d\n", answer); return0; }