Submission #385956

#TimeUsernameProblemLanguageResultExecution timeMemory
385956i_am_noobCarnival Tickets (IOI20_tickets)C++17
100 / 100
879 ms76040 KiB
#include<bits/stdc++.h> #include "tickets.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=1505; ll find_maximum(int k, vector<vector<int>> a) { int n = sz(a); int m = sz(a[0]); vector<vector<int>> res; res.resize(n); rep(n) res[i].resize(m); rep(n) rep1(j,m) res[i][j]=-1; ll ans=0; int l[maxn],r[maxn],curl[maxn],curr[maxn]; rep(n) l[i]=k-1,r[i]=m; priority_queue<pii> pq; rep(n) pq.push({a[i][k-1]+a[i][m-1],i}); rep1(_,n*k/2){ pii p=pq.top(); pq.pop(); int x=p.second; l[x]--; r[x]--; if(l[x]>=0) pq.push({a[x][l[x]]+a[x][r[x]-1],x}); } rep(n){ rep1(j,l[i]+1) ans-=a[i][j]; rep2(j,r[i],m) ans+=a[i][j]; } rep(n) curl[i]=0,curr[i]=m-1; int cntl,cntr; bool vis[maxn]; rep1(j,k){ cntl=n/2,cntr=n/2; rep(n) vis[i]=0; rep(n){ if(curl[i]>l[i]){ cntr--; res[i][curr[i]]=j; curr[i]--; vis[i]=1; } else if(curr[i]<r[i]){ cntl--; res[i][curl[i]]=j; curl[i]++; vis[i]=1; } } rep(n) if(!vis[i]){ if(cntl){ res[i][curl[i]]=j; curl[i]++; cntl--; } else{ res[i][curr[i]]=j; curr[i]--; cntr--; } } } allocate_tickets(res); return ans; }
#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...