이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define conts continue
#define sz(a) (int)a.size()
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &x, T y){
x = min(x,y);
}
template<typename T>
void amax(T &x, T y){
x = max(x,y);
}
template<typename A,typename B>
string to_string(pair<A,B> p);
string to_string(const string &s){
return "'"+s+"'";
}
string to_string(const char* s){
return to_string((string)s);
}
string to_string(bool b){
return b?"true":"false";
}
template<typename A>
string to_string(A v){
string res = "{";
trav(x,v){
res += to_string(x)+",";
}
if(res.back() == ',') res.pop_back();
res += "}";
return res;
}
template<typename A,typename B>
string to_string(pair<A,B> p){
return "("+to_string(p.ff)+","+to_string(p.ss)+")";
}
#define debug(x) cout << "[" << #x << "]: "; cout << to_string(x) << endl
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = 1e9 + 5;
const ll inf2 = (ll)1e18 + 5;
void solve(int test_case){
int n; cin >> n;
vector<array<int,3>> a(n+5);
rep1(i,n){
int r,c; cin >> r >> c;
char ch; cin >> ch;
swap(r,c);
int d = -1;
if(ch == 'E') d = 0;
if(ch == 'W') d = 1;
if(ch == 'S') d = 2;
if(ch == 'N') d = 3;
a[i] = {r,c,d};
}
map<int,set<pii>> mpr,mpc,mpsum,mpdiff;
rep1(i,n){
auto [r,c,d] = a[i];
mpr[r].insert({c,i});
mpc[c].insert({r,i});
mpsum[r+c].insert({r,i});
mpdiff[r-c].insert({r,i});
}
int mnt = 2*inf1;
vector<int> del;
auto upd = [&](int i, int j){
if(a[i][2] > a[j][2]) swap(i,j);
auto [ri,ci,di] = a[i];
auto [rj,cj,dj] = a[j];
if(di == dj) return;
int t = inf1;
if((di^1) == dj){
if(di == 0){
if(ci <= cj){
t = (cj-ci)/2;
}
}
else{
if(ri <= rj){
t = (rj-ri)/2;
}
}
}
else{
if(di == 0){
if(ci <= cj){
if(dj == 2){
if(ri-rj == cj-ci){
t = abs(ri-rj);
}
}
else{
if(rj-ri == cj-ci){
t = abs(ri-rj);
}
}
}
}
else{
if(ci >= cj){
if(dj == 2){
if(ri-rj == ci-cj){
t = abs(ri-rj);
}
}
else{
if(rj-ri == ci-cj){
t = abs(ri-rj);
}
}
}
}
}
if(t > mnt) return;
if(t < mnt){
del.clear();
}
mnt = t;
del.pb(i), del.pb(j);
};
vector<bool> rem(n+5);
while(true){
mnt = 2*inf1;
del.clear();
for(auto &mp : {mpr,mpc,mpsum,mpdiff}){
for(auto &[val,st] : mp){
int p = -1;
for(auto [c,i] : st){
if(p != -1){
upd(i,p);
}
p = i;
}
}
}
if(mnt == 2*inf1) break;
trav(i,del){
rem[i] = 1;
auto [r,c,d] = a[i];
mpr[r].erase({c,i});
mpc[c].erase({r,i});
mpsum[r+c].erase({r,i});
mpdiff[r-c].erase({r,i});
}
}
vector<int> ans;
rep1(i,n){
if(!rem[i]){
ans.pb(i);
}
}
trav(x,ans) cout << x << endl;
}
int main(){
fastio;
int t = 1;
// cin >> t;
rep1(i,t){
solve(i);
}
return 0;
}
# | 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... |