제출 #1134448

#제출 시각아이디문제언어결과실행 시간메모리
1134448iskhakkutbilimNaval battle (CEOI24_battle)C++20
6 / 100
3115 ms791588 KiB
#include "bits/stdc++.h"
using namespace std;

#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int N = 1e6;
const int LOG = 20;
const int INF = 1e9 + 7;

struct navy{
    int x, y;
    char c;
};


pair<int, int> move(char c){
    if(c == 'S') return {-1, 0};
    if(c == 'W') return {0, 1};
    if(c == 'N') return {1, 0};
    return {0, -1};
}

/*
2
2 4 E 
6 0 S
*/

int intersect(navy a, navy b){
    if(a.c != 'N') swap(a, b);
    if(a.c == 'N' && b.c == 'S' && b.y < a.y && a.x == b.y) return abs(b.y - a.y)/2;
    
    if(a.c != 'E') swap(a, b);
    if(a.c == 'E' && b.c == 'W' && a.y == b.y && a.x < b.x){
        return abs(b.x - a.x)/2;
    }
    if(a.c != 'E' and a.c != 'W') swap(a, b);
    if(abs(b.x - a.x) != abs(a.y - b.y) or abs(a.y - b.y)%2 != 0) return -1;
    
    
    if(a.c == 'E'){
        if(b.x > a.x){
            if(b.c == 'S' && b.y < a.y) return abs(b.x - a.x);
            if(b.c == 'N' && b.y > a.y) return abs(b.x - a.x);
        }
    }else if(a.c == 'W'){
        if(b.c == 'E' && a.y == b.y && a.x > b.y){
            return abs(b.x - a.x)/2;
        }
        if(b.x < a.x){
            if(b.c == 'N' && b.y > a.y) return abs(b.x - a.x);
            if(b.c == 'S' && b.y < a.y) return abs(b.x - a.x);
        }
    }
    
    return -1;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    
    int n; cin >> n;
    vector<navy> a(n);
    for(int i = 0;i < n; i++){
        cin >> a[i].x >> a[i].y >> a[i].c;
    }
    vector<int> used(n, 0);
    vector<array<int, 3> > pairs;
    for(int i = 0;i < n; i++){
        for(int j = 0;j < n; j++){
            if(i != j){
                int x = intersect(a[i], a[j]);
                if(x != -1){
                    pairs.push_back({i, j, x});
                }
            }
        }
    }
    sort(all(pairs), [&](auto A, auto B){
        return A[2] < B[2];
    });
    
    for(int i = 0;i < (int)pairs.size(); ){
        int j = i;
        while(j < (int)pairs.size() && pairs[j][2] == pairs[i][2]){
            used[pairs[j][0]] = 1;
            used[pairs[j][1]] = 1;
            j++;
        }
        i = j;
    }
    
    vector<int> answer;
    for(int i = 0;i < n; i++){
        if(!used[i]) answer.push_back(i+1);
    }
    for(auto x : answer) cout << x << '\n';
    return 0;
}
#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...