Submission #300675

#TimeUsernameProblemLanguageResultExecution timeMemory
300675errorgornCarnival Tickets (IOI20_tickets)C++14
100 / 100
1217 ms90744 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define ii pair<ll,ll> #define fi first #define se second #define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e)?x++:x--)) #define all(x) (x).begin(),(x).end() #define sz(x) (int) (x).size() const ll INF=1e18; int n,m,k; vector<vector<int> > arr; vector<vector<int> > state; vector<vector<int> > ans; vector<int> white[1505]; vector<int> black[1505]; bool vis[1505]; int pos[1505]; priority_queue<ii> pq; long long find_maximum(int _k, std::vector<std::vector<int>> _arr) { n=sz(_arr),m=sz(_arr[0]),arr=_arr; k=_k; rep(x,0,n){ ans.push_back(vector<int>()); rep(y,0,m) ans[x].push_back(-1); state.push_back(vector<int>()); rep(y,0,m) state[x].push_back(-1); pos[x]=k-1; pq.push(ii(arr[x][pos[x]+m-k]+arr[x][pos[x]],x)); } int node; rep(zzz,0,n*k/2){ node=pq.top().se,pq.pop(); state[node][pos[node]+m-k]=1; pos[node]--; if (pos[node]==-1) continue; pq.push(ii(arr[node][pos[node]+m-k]+arr[node][pos[node]],node)); } rep(x,0,n){ rep(y,0,pos[x]+1) state[x][y]=0; } ll res=0; rep(x,0,n){ rep(y,0,m){ //cout<<state[x][y]<<" "; if (state[x][y]==0){ res-=arr[x][y]; white[x].push_back(y); } else if (state[x][y]==1){ res+=arr[x][y]; black[x].push_back(y); } } //cout<<endl; } rep(idx,0,k){ memset(vis,false,sizeof(vis)); int currw=0; rep(x,0,n){ if (white[x].empty()){ vis[x]=true; ans[x][black[x].back()]=idx; black[x].pop_back(); } else if (black[x].empty()){ vis[x]=true; ans[x][white[x].back()]=idx; white[x].pop_back(); currw++; } } rep(x,0,n) if (!vis[x]){ if (currw==n/2){ ans[x][black[x].back()]=idx; black[x].pop_back(); } else { ans[x][white[x].back()]=idx; white[x].pop_back(); currw++; } } } allocate_tickets(ans); return res; }
#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...