Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <deque>
- #include <unordered_map>
- #include <unordered_set>
- #include <cmath>
- #include <iomanip>
- #include <utility>
- #include <string>
- #include <set>
- #include <map>
- #include <algorithm>
- using namespace std;
- bool comp(pair<int, bool> a, pair<int, bool> b) {
- return a.first <= b.first;
- }
- int main() {
- int n, m, q, a, b, g, h;
- string s;
- unordered_map<string, pair<int, int>> c;
- c["N"] = {0, 1};
- c["S"] = {0, -1};
- c["E"] = {1, 0};
- c["W"] = {-1, 0};
- unordered_map<string, string> shifts;
- shifts["N"] = "E";
- shifts["E"] = "S";
- shifts["S"] = "W";
- shifts["W"] = "N";
- cin >> n >> m >> q >> a >> b;
- --a;
- --b;
- for (int i = 0; i < q; ++i) {
- cin >> g >> h >> s;
- --g;
- --h;
- vector<vector<bool>> d(n, vector<bool>(m, false));
- d[g][h] = true;
- d[a][b] = true;
- int cnt = 0;
- while (true) {
- if (g + c[s].first >= 0 && h + c[s].second >= 0 && !d[g + c[s].first][h + c[s].second]) {
- d[g + c[s].first][h + c[s].second] = true;
- g += c[s].first;
- h += c[s].second;
- cnt++;
- continue;
- }
- s = shifts[s];
- if (g + c[s].first >= 0 && h + c[s].second >= 0 && !d[g + c[s].first][h + c[s].second]) {
- d[g + c[s].first][h + c[s].second] = true;
- g += c[s].first;
- h += c[s].second;
- cnt++;
- continue;
- }
- cout << cnt << "\n";
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement