Submission #1227294

#TimeUsernameProblemLanguageResultExecution timeMemory
1227294dreamxhavaNaval battle (CEOI24_battle)C++20
0 / 100
3095 ms2116 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; ios::sync_with_stdio(false); cin.tie(nullptr); vector<int> x(n), y(n); vector<char> d(n); vector<bool> active(n, true); vector<bool> collided(n, false); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i] >> d[i]; } int xmax = *max_element(x.begin(), x.end()); int ymax = *max_element(y.begin(), y.end()); if (n == 1) { cout << 1 << "\n"; return 0; } if (n == 2) { int x1 = x[0], y1 = y[0], x2 = x[1], y2 = y[1]; char d1 = d[0], d2 = d[1]; bool collided = false; for (int t = 0; t < 1000; t++) { if (x1 == x2 && y1 == y2) { collided = true; break; } int px1 = x1, py1 = y1, px2 = x2, py2 = y2; if (d1 == 'N') y1 -= 2; else if (d1 == 'S') y1 += 2; else if (d1 == 'E') x1 += 2; else if (d1 == 'W') x1 -= 2; if (d2 == 'N') y2 -= 2; else if (d2 == 'S') y2 += 2; else if (d2 == 'E') x2 += 2; else if (d2 == 'W') x2 -= 2; if (x1 == x2 && y1 == y2) { collided = true; break; } if (x1 == px2 && y1 == py2 && x2 == px1 && y2 == py1) { collided = true; break; } if (x1 > xmax || x1 < 0 || y1 > ymax || y1 < 0) break; if (x2 > xmax || x2 < 0 || y2 > ymax || y2 < 0) break; } if (!collided) { cout << 1 << "\n" << 2 << "\n"; } return 0; } bool moving = true; while (moving) { moving = false; for (int i = 0; i < n; i++) { if (!active[i]) continue; if (d[i] == 'N') y[i] -= 2; else if (d[i] == 'S') y[i] += 2; else if (d[i] == 'E') x[i] += 2; else if (d[i] == 'W') x[i] -= 2; if (x[i] > xmax || x[i] < 0 || y[i] > ymax || y[i] < 0) { active[i] = false; } else { moving = true; } } for (int i = 0; i < n; i++) { if (!active[i]) continue; for (int j = i + 1; j < n; j++) { if (!active[j]) continue; if (x[i] == x[j] && y[i] == y[j]) { collided[i] = true; collided[j] = true; active[i] = false; active[j] = false; } } } } for (int i = 0; i < n; i++) { if (!collided[i]) { cout << i + 1 << "\n"; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...