Submission #1068188

#TimeUsernameProblemLanguageResultExecution timeMemory
1068188vjudge1Naval battle (CEOI24_battle)C++17
46 / 100
2579 ms1048576 KiB
#include<bits/stdc++.h>
using namespace std;
long long int check(long long int x1, long long int y1, char c1, long long int x2,
long long int y2,char c2){
    if((c1 == 'N' or c1 == 'S') and (c2 == 'E' or c2 == 'W')){
        swap(x1,x2);
        swap(y1,y2);
        swap(c1,c2);
    }
    if(c1 == c2){
        return -1;
    }
    if(c1 == 'E'){
        if(c2 == 'W'){
            if(y1 != y2){
                return -1;
            }else{
                long long int res = (x2 - x1)/2;
                if(res > 0){
                return res;
                }else{
                    return -1;
                }
            }
        }
        if(c2 == 'N'){
            long long int a = x2 - x1;
            long long int b = y2 - y1;
            if(a == b and a > 0){
                return a;
            }else{
                return -1;
            }
        }

        if(c2 == 'S'){

            long long int a = x2 - x1;
            long long int b = y1 - y2;
            if(a == b and a > 0){
                return a;
            }else{
                return -1;
            }
        }
    }
    if(c1 == 'W'){
        if(c2 == 'E'){
            if(y1 != y2){
                return -1;
            }else{
                long long int res = (x1 - x2)/2;
                if(res > 0){
                return res;
                }else{
                    return -1;
                }
            }
        }
        if(c2 == 'N'){
            long long int a = x1 - x2;
            long long int b = y2 - y1;
            if(a == b and a > 0){
                return a;
            }else{
                return -1;
            }
        }
        if(c2 == 'S'){
            long long int a = x1 - x2;
            long long int b = y1 - y2;
            if(a == b and a > 0){
                return a;
            }else{
                return -1;
            }
        }
    }
    if(c1 == 'N'){
        if(x1 != x2){
            return -1;
        }
        long long int res = (y1 - y2) / 2;
        if(res > 0){
            return res;
        }
    }
    if(c1 == 'S'){
        if(x1 != x2){
            return -1;
        }
        long long int res = (y2 - y1) / 2;
        if(res > 0){
            return res;
        }
    }
    return -1;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    long long int x[n],y[n];
    long long int disa[n];
    char c[n];
   // cout << check(2,4,'E',4,2,'S');
    long long int INF = 1e18;
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> c[i];
        disa[i] = 1e18;
    }

    vector<pair<long long int,pair<int,int> > > v;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            long long int res =check(x[i],y[i],c[i],x[j],y[j],c[j]);
            //cout << res << endl;
            if(res != -1){
                v.push_back({res,{i,j}});
            }
        }
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < v.size(); i++){
        pair<int,int> x = v[i].second;
        int x1 = x.first;
        int x2 = x.second;
        if(disa[x1] >= v[i].first and disa[x2] >= v[i].first){
            disa[x1] = v[i].first;
            disa[x2] = v[i].first;
        }
    }
    for(int i = 0; i < n; i++){
        if(disa[i] == INF){
            cout << i + 1 << endl;
        }
    }


}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:125:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |     for(int i = 0; i < v.size(); i++){
      |                    ~~^~~~~~~~~~
#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...