작성
·
336
0
테스트 케이스도 다 맞고 질문 게시판의 추가 테스트케이스도 다 맞는데 어디서 오류가 나는것일까요 ..?
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
int arr[101][101];
char trans[101];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
queue<pair<int, int>> q;
pair<int, int> snake = {1, 1};
int N, K, L, X, Time, dir;
char C;
void IO() {
FIO;
cin >> N >> K;
for (int i = 0, x, y; i < K; i++) {
cin >> x >> y;
arr[x][y] = -1;
}
cin >> L;
for (int i = 0; i < L; i++) {
cin >> X;
cin >> trans[X];
}
}
int main() {
IO();
q.push({1, 1});
while (1) {
Time++;
int nx = snake.first + dx[dir];
int ny = snake.second + dy[dir];
q.push({nx, ny});
if (nx < 1 || nx > N || ny < 1 || ny > N || arr[nx][ny] > 0) break;
if (arr[nx][ny] != -1) {
int bx = q.front().first;
int by = q.front().second;
q.pop();
arr[bx][by] = 0;
}
arr[nx][ny] = Time;
if (trans[Time] == 'L') {
dir = dir - 1 < 0 ? 3 : dir - 1;
} else if (trans[Time] == 'D') {
dir = dir + 1 > 3 ? 0 : dir + 1;
}
snake = {nx, ny};
}
cout << Time;
return 0;
}