This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<tuple<int, int, char, int>> ships(n);
int ii = 0;
for (auto& [x, y, c, i] : ships)
cin >> x >> y >> c, i = ii++;
sort(ships.begin(), ships.end(),
[&](tuple<int, int, char, int> a, tuple<int, int, char, int> b) {
auto [x1, y1, c1, i1] = a;
auto [x2, y2, c2, i2] = b;
return x1+y1 < x2+y2 || x1 < x2;
});
int prev = 0;
stack<int> st;
vector<bool> sunk(n);
for (auto& [x, y, c, i] : ships) {
if (x+y != prev)
st = stack<int>{};
prev = x+y;
if (c == 'E')
st.push(i);
else if (!st.empty())
sunk[i] = true, sunk[st.top()] = true, st.pop();
}
for (int i = 0; i < n; i++)
if (!sunk[i])
cout << i+1 << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |