Submission #385970

#TimeUsernameProblemLanguageResultExecution timeMemory
385970i_am_noobComparing Plants (IOI20_plants)C++17
19 / 100
401 ms18304 KiB
#include<bits/stdc++.h> #include "plants.h" using namespace std; #define ll long long //#define int ll #define rep(n) rep1(i,n) #define rep1(i,n) rep2(i,0,n) #define rep2(i,a,b) for(int i=a; i<(b); ++i) #define rep3(i,a,b) for(int i=a; i>=(b); --i) #define pb push_back #define sz(a) ((int)a.size()) #define all(a) a.begin(),a.end() #define pii pair<int,int> #define inf 0x3f3f3f3f3f3f3f3f #define pow2(x) (1ll<<(x)) #ifdef i_am_noob #define bug(...) cerr << "#" << __LINE__ << " " << #__VA_ARGS__ << "- ", _do(__VA_ARGS__) template<typename T> void _do(T x){cerr << x << endl;} template<typename T, typename ...S> void _do(T x, S... y){cerr << x << ", ";_do(y...);} #else #define bug(...) 49 #endif const int maxn=200005; int n,k,sum[maxn],a[maxn]; vector<int> r; void init(int _k, vector<int> _r){ k=_k; r=_r; n=sz(r); rep(n) sum[i+1]=sum[i]+r[i]; set<int> st; rep(n) if(r[i]==0) st.insert(i); int maxx,maxid; vector<int> vec; if(n<5005){ bool flag; rep3(i,n-1,0){ flag=0; maxx=(*st.begin())-(*st.rbegin())+n; maxid=*st.begin(); vec.clear(); for(auto j: st) vec.pb(j); rep2(j,1,sz(vec)) if(vec[j]-vec[j-1]>maxx) maxx=vec[j]-vec[j-1],maxid=vec[j]; a[maxid]=i; rep1(ii,k-1){ r[(maxid-ii-1+n)%n]--; if(r[(maxid-ii-1+n)%n]==0) st.insert((maxid-ii-1+n)%n); } r[maxid]=n; st.erase(maxid); } } } int compare_plants(int x, int y) { if(k==2){ if(sum[y]-sum[x]==y-x) return -1; if(sum[y]-sum[x]==0) return 1; if(sum[n]-sum[y]+sum[x]==n-y+x) return 1; if(sum[n]-sum[y]+sum[x]==0) return -1; return 0; } return a[x]>a[y]?1:-1; }

Compilation message (stderr)

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:43:11: warning: variable 'flag' set but not used [-Wunused-but-set-variable]
   43 |      bool flag;
      |           ^~~~
#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...