-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ3190_뱀.cpp
More file actions
67 lines (64 loc) · 1.36 KB
/
BOJ3190_뱀.cpp
File metadata and controls
67 lines (64 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// main.cpp
// BOJ3190_뱀
//
// Created by 신지식 on 2018. 10. 16..
// Copyright © 2018년 Shin Ji Sik. All rights reserved.
//
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
int d[100][100];
bool apple[100][100];
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
int main() {
int n;
cin >> n;
int m;
cin >> m;
while (m--) {
int x, y;
cin >> x >> y;
apple[x-1][y-1] = true;
}
memset(d,-1,sizeof(d));
int x = 0;
int y = 0;
int dir = 0;
int len = 1;
d[x][y] = 0;
cin >> m;
int now = 0;
for (int k=0; k<=m; k++) {
int t = n*n+1;
char ch = 'L';
if (k < m) {
cin >> t >> ch;
}
while (now < t) {
now += 1;
x += dx[dir];
y += dy[dir];
if (x < 0 || x >= n || y < 0 || y >= n) {
cout << now << '\n';
return 0;
}
if (apple[x][y]) {
apple[x][y] = false;
len += 1;
}
if (d[x][y] != -1 && now-d[x][y] <= len) {
cout << now << '\n';
return 0;
}
d[x][y] = now;
}
if (ch == 'L')
dir = (dir + 3) % 4;
else
dir = (dir + 1) % 4;
}
return 0;
}