Submission #1068327

#TimeUsernameProblemLanguageResultExecution timeMemory
1068327glupanNaval battle (CEOI24_battle)C++14
6 / 100
3056 ms790120 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]; 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 or destroyed[explosion.second.first] == explosion.first or destroyed[explosion.second.second] == explosion.first) { destroyed[explosion.second.first] = explosion.first; destroyed[explosion.second.second] = 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 'int sudar(int, int, char, int, int, char)':
Main.cpp:19:18: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   19 |     if(d1 == 'E' and d2 == 'N' or d1 == 'S' and d2 == 'N' or d1 == 'S' and d2 == 'E' or d1 == 'W') {
      |        ~~~~~~~~~~^~~~~~~~~~~~~
Main.cpp:19:72: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   19 |     if(d1 == 'E' and d2 == 'N' or d1 == 'S' and d2 == 'N' or d1 == 'S' and d2 == 'E' or d1 == 'W') {
      |                                                              ~~~~~~~~~~^~~~~~~~~~~~~
Main.cpp: In function 'void solve()':
Main.cpp:69:51: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   69 |         if(destroyed[explosion.second.first] == 0 and destroyed[explosion.second.second] == 0 or destroyed[explosion.second.first] == explosion.first or destroyed[explosion.second.second] == explosion.first) {
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 | }
      | ^
#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...