제출 #601275

#제출 시각아이디문제언어결과실행 시간메모리
601275yutabi식물 비교 (IOI20_plants)C++14
25 / 100
4091 ms4980 KiB
#include "plants.h" #include <bits/stdc++.h> using namespace std; #define pb push_back int n; vector <int> ans; vector <vector <int> > graph; bool table[300][300]; int K; void init(int k, std::vector<int> r) { K=k; n=r.size(); ans=vector <int> (n); if(n<=300) { graph.resize(n); for(int i=0;i<n;i++) { int loc; int last=-1; for(int j=n-k;j<n;j++) { if(r[j]==0) { last=j; } } for(int j=0;j<n;j++) { if(r[j]==0) { if(last==-1 || (last<j && last+k<=j) || (last>j && j+n-k>=last) || j==last) { loc=j; break; } last=j; } } r[loc]=n*4; for(int j=(loc-k+1+n)%n;j!=loc;j=(j+1)%n) { r[j]--; if(r[j]<=n) { graph[j].pb(loc); } } for(int j=(loc+k-1)%n;j!=loc;j=(j-1+n)%n) { if(r[j]<=n) { graph[j].pb(loc); } } /*for(int j=0;j<n;j++) { printf("%d ",r[j]); } printf("\n");*/ } /*for(int i=0;i<n;i++) { printf("%d: ",i); for(int j=0;j<graph[i].size();j++) { printf("%d ",graph[i][j]); } printf("\n"); }*/ for(int j=0;j<n;j++) { vector <bool> v(n,0); stack <int> st; st.push(j); while(st.size()) { int node=st.top(); st.pop(); v[node]=1; for(int k=0;k<graph[node].size();k++) { if(v[graph[node][k]]==0) { st.push(graph[node][k]); v[graph[node][k]]=1; } } } for(int k=0;k<n;k++) { if(v[k]) { table[j][k]=1; } } } } else if(k!=2) { for(int i=0;i<n;i++) { int loc; int last=-1; for(int j=n-k;j<n;j++) { if(r[j]==0) { last=j; } } for(int j=0;j<n;j++) { if(r[j]==0) { if(last==-1 || (last<j && last+k<=j) || (last>j && j+n-k>=last) || j==last) { loc=j; break; } last=j; } } r[loc]=n*4; ans[loc]=i; for(int j=(loc-k+1+n)%n;j!=loc;j=(j+1)%n) { r[j]--; } /*for(int j=0;j<n;j++) { printf("%d ",r[j]); } printf("\n");*/ } } else { } return; } int compare_plants(int x, int y) { if(n<=300) { if(table[x][y]) { return -1; } if(table[y][x]) { return 1; } return 0; } if(K!=2) { if(ans[x]<ans[y]) { return 1; } return -1; } }

컴파일 시 표준 에러 (stderr) 메시지

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:112:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |     for(int k=0;k<graph[node].size();k++)
      |                 ~^~~~~~~~~~~~~~~~~~~
plants.cpp: In function 'int compare_plants(int, int)':
plants.cpp:214:1: warning: control reaches end of non-void function [-Wreturn-type]
  214 | }
      | ^
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:162:9: warning: 'loc' may be used uninitialized in this function [-Wmaybe-uninitialized]
  162 |    r[loc]=n*4;
      |         ^
#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...