Submission #1068746

#TimeUsernameProblemLanguageResultExecution timeMemory
1068746vjudge1Naval battle (CEOI24_battle)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#define div /
#define ll long long

#define fore(i, l, r) for(int i=int(l); i<int(r); i++)
#define sz(a) int((a).size())

using namespace std;

const int INF = 1e9;
const int MX = 5e5 + 23;
const int MOD = 1000000007;
const int MAX_N = 5e5+23;
const int N = 1e6;

int sudar(int x1, int y1, char d1, int x2, int y2, char d2) {
    if(d1 == d2)
        return 0;
    if((d1 == 'E' and d2 == 'N') or (d1 == 'S' and d2 == 'N') or (d1 == 'S' and d2 == 'E') or (d1 == 'W')) {
        swap(d1,d2);
        swap(x1,x2);
        swap(y1,y2);
    }
    if(d1 == 'N') {
        if(d2 == 'S') {
            if((x1 != x2) or (y1 < y2)) return 0;
            return (y1-y2)/2;
        } else if(d2 == 'E') {
            if((y2 > y1) or (x2 > x1) or ((y1-y2) != (x1-x2))) return 0;
            return (x1-x2);
        } else if(d2 == 'W') {
            if((y2 > y1) or (x2 < x1) or ((y1-y2) != (x2-x1))) return 0;
            return (x2-x1);
        }
    } else if(d1 == 'E') {
        if(d2 == 'W') {
            if((y1 != y2) or (x1 > x2)) return 0;
            return (x2-x1)/2;
        } else if(d2 == 'S') {
            if((y2 > y1) or (x2 < x1) or ((y1-y2) != (x2-x1))) return 0;
            return (x2-x1);
        }
    } else if(d1 == 'S') {
        if(d2 == 'W') {
            if((y1 > y2) or (x1 > x2) or ((y2-y1) != (x2-x1))) return 0;
            return (x2-x1);
        }
    }
}

void solve() {
    int n; cin >> n;
    int x[n],y[n],destroyed[n+5];
    memset(destroyed,0,sizeof destroyed);
    char d[n];
    fore(i,0,n)
        cin >> x[i] >> y[i] >> d[i];
    priority_queue<pair<int,pair<int,int>>>pq;
    fore(i,0,n) {
        fore(j,0,n) {
            if(sudar(x[i],y[i],d[i],x[j],y[j],d[j]))
                pq.push({sudar(x[i],y[i],d[i],x[j],y[j],d[j]),{i,j}});
            }
        }
        int destroyed[n+5];
        memset(destroyed,0,sizeof destroyed);
        while(!pq.empty()) {
            pair<int,pair<int,int>> explosion = pq.top();
            pq.pop();
            if(destroyed[explosion.second.first] == 0 and destroyed[explosion.second.second] == 0) {
                destroyed[explosion.second.first] = explosion.first;
                destroyed[explosion.second.second] = explosion.first;
            } else if(destroyed[explosion.second.first] == explosion.first and destroyed[explosion.second.second] == 0) {
                destroyed[explosion.second.second] = explosion.first;
            } else if(destroyed[explosion.second.first] == 0 and destroyed[explosion.second.second] == explosion.first) {
                destroyed[explosion.second.first] = explosion.first;
            }
        }
        fore(i,0,n)
            if(!destroyed[i])
                cout << i+1 << endl;
    }
}

int main() {
    ios::sync_with_stdio(false);

    int t=1;
    while(t--) solve();
}

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:65:13: error: redeclaration of 'int destroyed [(n + 5)]'
   65 |         int destroyed[n+5];
      |             ^~~~~~~~~
Main.cpp:53:19: note: 'int destroyed [(n + 5)]' previously declared here
   53 |     int x[n],y[n],destroyed[n+5];
      |                   ^~~~~~~~~
Main.cpp: At global scope:
Main.cpp:83:1: error: expected declaration before '}' token
   83 | }
      | ^
Main.cpp: In function 'int sudar(int, int, char, int, int, char)':
Main.cpp:49:1: warning: control reaches end of non-void function [-Wreturn-type]
   49 | }
      | ^