제출 #1134621

#제출 시각아이디문제언어결과실행 시간메모리
1134621viwlesxqNaval battle (CEOI24_battle)C++20
46 / 100
356 ms49708 KiB
#include <bits/stdc++.h> using namespace std; #define int long long template<class A, class B> bool chmin(A &a, const B &b) { return a > b ? (a = b) == b : false; } template<class A, class B> bool chmax(A &a, const B &b) { return a < b ? (a = b) == b : false; } const int inf = 1e18; signed main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; int x[n], y[n]; char d[n]; for (int i = 0; i < n; ++i) { cin >> x[i] >> y[i] >> d[i]; } if (n <= 5000) { vector<array<int, 3>> v; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (d[i] == d[j]) continue; if (d[i] == 'N' && d[j] == 'S') { if (x[i] == x[j] && y[i] > y[j]) v.push_back({(y[i] - y[j]) / 2, i, j}); } else if (d[i] == 'N' && d[j] == 'E') { if (x[i] > x[j] && x[i] - y[i] == x[j] - y[j]) v.push_back({x[i] - x[j], i, j}); } else if (d[i] == 'N' && d[j] == 'W') { if (x[j] > x[i] && x[j] + y[j] == x[i] + y[i]) v.push_back({x[j] - x[i], i, j}); } else if (d[i] == 'S' && d[j] == 'E') { if (x[i] > x[j] && x[i] + y[i] == x[j] + y[j]) v.push_back({x[i] - x[j], i, j}); } else if (d[i] == 'S' && d[j] == 'W') { if (x[j] > x[i] && x[j] - y[j] == x[i] - y[i]) v.push_back({x[j] - x[i], i, j}); } else if (d[i] == 'E' && d[j] == 'W') { if (y[i] == y[j] && x[i] < x[j]) v.push_back({(x[j] - x[i]) / 2, i, j}); } } } sort(v.begin(), v.end()); vector<int> del(n, inf); for (auto [t, i, j] : v) { if (del[i] < t || del[j] < t) continue; del[i] = del[j] = t; } for (int i = 0; i < n; ++i) { if (del[i] == inf) { cout << i + 1 << '\n'; } } return 0; } map<int, vector<int>> mp; for (int i = 0; i < n; ++i) { mp[x[i] + y[i]].push_back(i); } int res = 0; for (auto &[k, v] : mp) { sort(v.begin(), v.end(), [&](int i, int j) { return y[i] < y[j]; }); stack<int> stk; for (auto i : v) { if (d[i] == 'S') { stk.push(0); } else { if (!stk.empty() && !stk.top()) stk.pop(); else stk.push(1); } } res += stk.size(); } cout << res; }
#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...