-
Notifications
You must be signed in to change notification settings - Fork 14
/
2020-1C-overexcited-fan.cpp
36 lines (32 loc) 路 1004 Bytes
/
2020-1C-overexcited-fan.cpp
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
/*
ad-hoc
difficulty: easy
date: 02/May/2020
by: @brpapa
*/
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
int main() {
int T; cin >> T;
for (int t = 1; t <= T; t++) {
int x, y; cin >> x >> y;
string m; cin >> m;
vector<ii> path;
path.push_back(ii(x, y)); // time 0
for (char c : m) {
if (c == 'N') path.push_back(ii(path.back().first, path.back().second+1));
if (c == 'E') path.push_back(ii(path.back().first+1, path.back().second));
if (c == 'S') path.push_back(ii(path.back().first, path.back().second-1));
if (c == 'W') path.push_back(ii(path.back().first-1, path.back().second));
}
int ans = -1;
for (int i = 0; i < path.size() && ans == -1; i++)
if (abs(path[i].first) + abs(path[i].second) <= i)
ans = i;
printf("Case #%d: ", t);
if (ans == -1) cout << "IMPOSSIBLE"; else cout << ans;
cout << endl;
}
return 0;
}