Snail Path
Problem LinkSolution by TioPatinhas — 100 pts
Code / Notes
#include <bits/stdc++.h>
using namespace std;
// Problema Atual: 6
int main() {
int m;
cin >> m;
int x = 0;
int y = 0;
map<pair<int,int>, int>M;
M[{0,0}] = 1;
int cnt = 0;
for (int i = 0; i < m; i++) {
char Ai;
cin >> Ai;
int c;
cin >> c;
if (Ai == 'N') {
for (int j = 1; j <= c; j++) {
if (M[{x, y+j}] == 1) cnt++;
else M[{x,y+j}] = 1;
}
y += c;
}
if (Ai == 'S') {
for (int j = 1; j <= c; j++) {
if (M[{x, y-j}] == 1) cnt++;
else M[{x,y-j}] = 1;
}
y -= c;
}
if (Ai == 'W') {
for (int j = 1; j <= c; j++) {
if (M[{x-j,y}] == 1) cnt++;
else M[{x-j,y}] = 1;
}
x -= c;
}
if (Ai == 'E') {
for (int j = 1; j <= c; j++) {
if (M[{x+j,y}] == 1) cnt++;
else M[{x+j,y}] = 1;
}
x += c;
}
}
cout << cnt << endl;
}
Last updated 14 hours, 30 minutes ago