Skip to content

Commit 3adc618

Browse files
authored
[20251021] BOJ / P4 / 경로 수정하기 / 권혁준
1 parent 3285c0b commit 3adc618

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
```cpp
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
int N, Q;
6+
int U = 0, D = 0, L = 0, R = 0, X = 0, Y = 0;
7+
8+
int main() {
9+
cin.tie(0)->sync_with_stdio(0);
10+
11+
cin >> N >> Q;
12+
for (int i = 0; i < N; i++) {
13+
char a;
14+
cin >> a;
15+
if (a == 'U') U++, Y++;
16+
if (a == 'D') D++, Y--;
17+
if (a == 'L') L++, X--;
18+
if (a == 'R') R++, X++;
19+
}
20+
21+
for (int x, y; Q--;) {
22+
cin >> x >> y;
23+
int xDiff = abs(x - X), yDiff = abs(y - Y);
24+
if (abs(x) + abs(y) > N || (x + y) % 2 != (X + Y) % 2) {
25+
cout << "-1\n";
26+
continue;
27+
}
28+
cout << (xDiff + yDiff) / 2 << '\n';
29+
}
30+
31+
}
32+
```

0 commit comments

Comments
 (0)