Submission #54360

#TimeUsernameProblemLanguageResultExecution timeMemory
54360khsoo01Flood (IOI07_flood)C++11
100 / 100
141 ms7564 KiB
#include<bits/stdc++.h> #define X first #define Y second using namespace std; typedef pair<int,int> pii; const int N = 200005; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, -1, 0, 1}; int n, m, x[N], y[N], a[N], b[N], nxt[N][4]; bool col[N], vis[N][2]; vector<int> wait, ans; priority_queue<pair<pii,int> > pq; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d%d",&x[i],&y[i]); } scanf("%d",&m); for(int i=1;i<=m;i++) { int A, B; scanf("%d%d",&A,&B); if(x[A] > x[B] || y[A] > y[B]) swap(A, B); a[i] = A; b[i] = B; if(y[A] == y[B]) { nxt[A][0] = i; nxt[B][2] = i; } else { nxt[A][3] = i; nxt[B][1] = i; } pq.push({{x[B], -y[B]}, i}); } while(!pq.empty()) { int T = pq.top().Y; pq.pop(); if(col[T]) continue; int V = a[T], P = (x[a[T]] == x[b[T]] ? 1 : 2); for(;;) { int D, Z; for(int i=0;i<4;i++) { D = (P + 3 + i) % 4; Z = nxt[V][D]; if(Z && !col[Z]) break; } if(vis[Z][D<2]) break; vis[Z][D<2] = true; wait.push_back(Z); V = a[Z] + b[Z] - V; P = D; } for(auto &T : wait) { col[T] = true; } wait.clear(); } for(int i=1;i<=m;i++) { if(vis[i][0] && vis[i][1]) ans.push_back(i); } printf("%d\n",(int)ans.size()); sort(ans.begin(), ans.end()); for(auto &T : ans) { printf("%d\n",T); } }

Compilation message (stderr)

flood.cpp: In function 'int main()':
flood.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
flood.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&x[i],&y[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~
flood.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&m);
  ~~~~~^~~~~~~~~
flood.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&A,&B);
   ~~~~~^~~~~~~~~~~~~~
#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...
#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...