1 条题解
-
1
#include <map> #include <vector> #include <climits> using namespace std; int main() { int N; cin >> N; map<pair<int,int>, vector<int>> visits; int x = 0, y = 0, t = 0; visits[{x, y}].push_back(t); for (int i = 0; i < N; i++) { char dir; int steps; cin >> dir >> steps; for (int s = 0; s < steps; s++) { if (dir == 'N') y++; else if (dir == 'E') x++; else if (dir == 'S') y--; else x--; t++; visits[{x, y}].push_back(t); } } int ans = INT_MAX; for (auto& p : visits) { auto& times = p.second; for (int i = 1; i < (int)times.size(); i++) { ans = min(ans, times[i] - times[i - 1]); } } if (ans == INT_MAX) cout << -1 << endl; else cout << ans << endl; return 0; }
- 1
信息
- ID
- 2230
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 3
- 已通过
- 2
- 上传者