이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int nx=2e5+5;
int n, x[nx], y[nx], dn[nx];
char dr[nx];
struct ship
{
vector<pair<int, int>> s, e;
};
map<int, ship> mp;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++)
{
cin>>x[i]>>y[i]>>dr[i];
if (dr[i]=='S') mp[x[i]+y[i]].s.push_back({x[i], i});
else mp[x[i]+y[i]].e.push_back({x[i], i});
}
for (auto &[_, t]:mp)
{
//cout<<"debug "<<_<<'\n';
sort(t.e.begin(), t.e.end());
sort(t.s.begin(), t.s.end());
//for (auto x:t.s) cout<<"S "<<x.first<<' '<<x.second<<'\n';
//for (auto x:t.e) cout<<"E "<<x.first<<' '<<x.second<<'\n';
stack<int> st;
while (!t.e.empty()||!t.s.empty())
{
//cout<<"s "<<t.e.empty()<<'\n';
if (t.e.empty()||(!t.s.empty()&&t.s.back()>t.e.back())) st.push(t.s.back().second), t.s.pop_back();
else
{
if (!st.empty()) dn[t.e.back().second]=dn[st.top()]=1, st.pop();
t.e.pop_back();
}
}
}
for (int i=1; i<=n; i++) if (!dn[i]) cout<<i<<'\n';
}
/*
8
3 0 S
4 0 S
2 1 E
1 2 E
5 2 S
4 3 S
0 5 E
2 5 E
*/
# | 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... |