Submission #121245

#TimeUsernameProblemLanguageResultExecution timeMemory
121245PlurmFlood (IOI07_flood)C++11
26 / 100
183 ms12520 KiB
#include <bits/stdc++.h> #define get(a,b) (ev[g[a][b]].first ^ ev[g[a][b]].second ^ a) using namespace std; int x[100005]; int y[100005]; int g[100005][4]; // U, L, D, R class Compare{ public: bool operator()(int x, int y){ return ::x[x] < ::x[y]; } }; int prior[4][4] = { {1, 0, 3, 2}, // U {2, 1, 0, 3}, // L {3, 2, 1, 0}, // D {0, 3, 2, 1} }; int inv[4] = {2, 3, 0, 1}; bool deleted[200005]; vector<pair<int,int> > ev; void deleteEdge(int idx){ int u = ev[idx].first; int v = ev[idx].second; for(int i = 0; i < 4; i++){ int j = inv[i]; if(get(u,i) == v && get(v,j) == u){ g[u][i] = -1; g[v][j] = -1; } } } int main(){ memset(g, -1, sizeof(g)); int n; scanf("%d",&n); multiset<int, Compare> ms; for(int i = 1; i <= n; i++){ scanf("%d%d",x+i,y+i); } for(int i = 1; i <= n; i++){ ms.insert(i); } int w; scanf("%d",&w); for(int i = 0; i < w; i++){ int a,b; scanf("%d%d",&a,&b); if(x[a] > x[b]) swap(a,b); if(y[a] > y[b]) swap(a,b); if(x[a] < x[b]){ g[a][3] = i; g[b][1] = i; }else{ g[a][0] = i; g[b][2] = i; } ev.push_back(make_pair(a,b)); } while(!ms.empty()){ int c = *ms.begin(); int state = 0; // 0: Going up // 1: Going left // 2: Going down // 3: Going right int u = c; vector<int> tour; vector<int> edge; map<int,int> ecnt; // U L D R do{ // Trace the border tour.push_back(u); for(int i = 0; i < 4; i++){ int chdir = prior[state][i]; if(g[u][chdir] != -1){ state = chdir; ecnt[g[u][chdir]]++; edge.push_back(g[u][chdir]); u = get(u,chdir); break; } } }while(u != c); for(int i = 0; i < edge.size(); i++){ int en = edge[i]; deleteEdge(en); if(ecnt[en] % 2 == 0) continue; deleted[en] = true; } for(int i = 0; i < tour.size(); i++){ int cnt = 0; for(int j = 0; j < 4; j++) if(g[tour[i]][j] != -1) cnt++; if(cnt == 0) ms.erase(tour[i]); } } vector<int> ans; for(int i = 0; i < w; i++){ if(!deleted[i]){ ans.push_back(i+1); } } printf("%d\n",ans.size()); for(int i = 0; i < ans.size(); i++){ printf("%d\n",ans[i]); } return 0; } /* 15 1 1 8 1 4 2 7 2 2 3 4 3 6 3 2 5 4 5 6 5 4 6 7 6 1 8 4 8 8 8 17 1 2 2 15 15 14 14 13 13 1 14 11 11 12 12 4 4 3 3 6 6 5 5 8 8 9 9 11 9 10 10 7 7 6 */

Compilation message (stderr)

flood.cpp: In function 'int main()':
flood.cpp:86:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < edge.size(); i++){
                        ~~^~~~~~~~~~~~~
flood.cpp:92:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < tour.size(); i++){
                        ~~^~~~~~~~~~~~~
flood.cpp:104:29: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n",ans.size());
                   ~~~~~~~~~~^
flood.cpp:105:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < ans.size(); i++){
                    ~~^~~~~~~~~~~~
flood.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
flood.cpp:39:14: 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:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&w);
     ~~~~~^~~~~~~~~
flood.cpp:48:14: 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...