제출 #1341257

#제출 시각아이디문제언어결과실행 시간메모리
1341257nathjessNaval battle (CEOI24_battle)C++20
46 / 100
641 ms98912 KiB
# include<bits/stdc++.h>
# define int long long
# define vi vector<int>
# define fi first 
# define se second 
# define pb push_back
# define pii pair<int, int>
# define endl '\n'

using namespace std;

int n, x[5005], y[5005];
char c[5005];
bool st[5005];

void solve() {
    cin >> n;
    for(int i=1; i<=n; i++) {
        cin >> x[i] >> y[i] >> c[i];
    }
    vector<pair<int, pii>> v;
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=n; j++) {
            if(i==j) continue;
            if(c[i]==c[j]) continue;
            if(c[i]=='E') {
                if(c[j]=='W') {
                    if(y[i]==y[j] && x[i]<x[j] && (x[j]-x[i])%2==0) {
                        v.pb({(x[j]-x[i])/2, {i, j}});
                    }
                }
                else if(c[j]=='S') {
                    if(((x[i]+y[i])==(x[j]+y[j])) && x[i]<x[j] && y[j]<y[i]) {
                        v.pb({y[i]-y[j], {i, j}});
                    }
                }
                else if(c[j]=='N') {
                    if(((x[i]-y[i])==(x[j]-y[j])) && x[i]<x[j] && y[i]<y[j]) {
                        v.pb({y[j]-y[i], {i, j}});
                    }
                }
            }
            else if(c[i]=='S') {
                if(c[j]=='N') {
                    if(x[i]==x[j] && y[i]<y[j] && (y[j]-y[i])%2==0) {
                        v.pb({(y[j]-y[i])/2, {i, j}});
                    }
                }
                else if(c[j]=='E') {
                    if(((x[i]+y[i])==(x[j]+y[j])) && x[j]<x[i] && y[i]<y[j]) {
                        v.pb({y[j]-y[i], {i, j}});
                    }
                }
                else if(c[j]=='W') {
                    if(((x[i]-y[i])==(x[j]-y[j])) && x[i]<x[j] && y[i]<y[j]) {
                        v.pb({y[j]-y[i], {i, j}});
                    }
                }
            }
            else if(c[i]=='W') {
                if(c[j]=='E') {
                    if(y[i]==y[j] && x[j]<x[i] && (x[i]-x[j])%2==0) {
                        v.pb({(x[i]-x[j])/2, {i, j}});
                    }
                }
                else if(c[j]=='N') {
                    if(((x[i]+y[i])==(x[j]+y[j])) && x[j]<x[i] && y[i]<y[j]) {
                        v.pb({y[j]-y[i], {i, j}});
                    }
                }
                else if(c[j]=='S') {
                    if(((x[i]-y[i])==(x[j]-y[j])) && x[j]<x[i] && y[j]<y[i]) {
                        v.pb({y[i]-y[j], {i, j}});
                    }
                }
            }
            else if(c[i]=='N') {
                if(c[j]=='S') {
                    if(x[i]==x[j] && y[i]>y[j] && (y[i]-y[j])%2==0) {
                        v.pb({(y[i]-y[j])/2, {i, j}});
                    }
                }
                else if(c[j]=='W') {
                    if(((x[i]+y[i])==(x[j]+y[j])) && x[i]<x[j] && y[j]<y[i]) {
                        v.pb({y[i]-y[j], {i, j}});
                    }
                }
                else if(c[j]=='E') {
                    if(((x[i]-y[i])==(x[j]-y[j])) && x[j]<x[i] && y[j]<y[i]) {
                        v.pb({y[i]-y[j], {i, j}});
                    }
                }
            }
        }
    }
    sort(v.begin(), v.end());
    queue<int> q;
    for(int i=0; i<v.size(); i++) {
        // cout << "step " << i << " : " << v[i].fi << " " << v[i].se.fi << " " << v[i].se.se << endl;
        if(!st[v[i].se.fi] && !st[v[i].se.se]) {
            q.push(v[i].se.fi);
            q.push(v[i].se.se);
        }
        if((i+1)<v.size() && v[i+1].fi!=v[i].fi) {
            while(!q.empty()) {
                st[q.front()]=1;
                q.pop();
            }  
        }
    }
    while(!q.empty()) {
        st[q.front()]=1;
        q.pop();
    }  
    for(int i=1; i<=n; i++) {
        if(!st[i]) cout << i << endl;
    }
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    solve();
}
#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...