Submission #337332

#TimeUsernameProblemLanguageResultExecution timeMemory
337332MvCCarnival Tickets (IOI20_tickets)C++17
11 / 100
3 ms1024 KiB
#include "tickets.h" #include <bits/stdc++.h> #define rc(x) return cout<<x<<endl,0 #define pb push_back #define mkp make_pair #define in insert #define er erase #define fd find #define fr first #define sc second #define all(x) x.begin(),x.end() #define lun(x) (int)x.size() typedef long long ll; typedef long double ld; const ll INF=0x3f3f3f3f3f3f3f3f; const ll llinf=(1LL<<60); const int inf=(1<<30); const int nmax=2e3+50; const ll mod=1e9+7; using namespace std; int n,m,i,j,nr,vz[nmax]; vector<vector<int> >rs; vector<pair<vector<int>,int> >s,b; vector<pair<int,pair<int,int> > >vc; vector<int>v[2][nmax]; ll sm; ll find_maximum(int k,vector<vector<int> > a) { n=lun(a),m=lun(a[0]); for(i=0;i<n;i++)for(j=0;j<m;j++)vc.pb(mkp(a[i][j],mkp(i,j))); sort(all(vc)); for(i=0;i<n*m;i++) { v[i<n*m/2][vc[i].sc.fr].pb(vc[i].sc.sc); if(i<n*m/2)sm-=1LL*vc[i].fr; else sm+=1LL*vc[i].fr; } for(i=0;i<n;i++) { if(!v[0][i].empty())b.pb(mkp(v[0][i],i)); if(!v[1][i].empty())s.pb(mkp(v[1][i],i)); } rs.resize(n); for(i=0;i<n;i++)for(j=0;j<m;j++)rs[i].pb(-1); for(i=0;i<k;i++) { for(j=0;j<n;j++)vz[j]=0; nr=0; for(j=0;j<lun(s);j++) { if(nr==n/2)break; if(s[j].fr.empty())continue; vz[s[j].sc]=1; rs[s[j].sc][s[j].fr.back()]=i; s[j].fr.pop_back(); nr++; } assert(nr==n/2); nr=0; for(j=0;j<lun(b);j++) { if(nr==n/2)break; if(b[j].fr.empty() || vz[b[j].sc])continue; vz[b[j].sc]=1; rs[b[j].sc][b[j].fr.back()]=i; b[j].fr.pop_back(); nr++; } assert(n/2==nr); } allocate_tickets(rs); return sm; } /*int main() { //freopen("sol.in","r",stdin); //freopen("sol.out","w",stdout); //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0); return 0; }*/
#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...