Submission #1068512

#TimeUsernameProblemLanguageResultExecution timeMemory
1068512vjudge1Naval battle (CEOI24_battle)C++17
18 / 100
3051 ms7072 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]; if(n == 2) { 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; } else { fore(korak,1,101) { fore(i,0,n) { if(destroyed[i]) continue; if(d[i] == 'E') x[i]++; else if(d[i] == 'W') x[i]--; else if(d[i] == 'N') y[i]--; else y[i]++; } fore(i,0,n-1) { fore(j,i+1,n) { if(i == j or (destroyed[i] and destroyed[i] < korak) or (destroyed[j] and destroyed[j] < korak)) continue; if(x[i] == x[j] and y[i] == y[j]) { destroyed[i] = korak; destroyed[j] = korak; } } } } 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: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...