Submission #793054

#TimeUsernameProblemLanguageResultExecution timeMemory
793054KhizriCarnival Tickets (IOI20_tickets)C++17
55 / 100
643 ms88804 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define F first #define S second #define INF 1e18 #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define pii pair<int,int> #define pll pair<ll,ll> #define OK cout<<"Ok"<<endl; #define MOD (ll)(1e9+7) const int mxn=1500+5; ll n,m,l[mxn],mid[mxn],r[mxn],sz[mxn],pre[mxn][mxn]; vector<vector<int>>vt; bool cmp(int a,int b){ ll x=pre[a][mid[a]],y=pre[b][mid[b]]; if(l[a]-1>=0){ x-=pre[a][l[a]-1]; } if(l[b]-1>=0){ y-=pre[b][l[b]-1]; } return vt[a][r[a]]+x>vt[b][r[b]]+y; } bool cmp2(int i,int j){ return sz[i]>sz[j]; } long long find_maximum(int k, vector<vector<int>> x) { vt=x; n = x.size(); m = x[0].size(); for(int i=0;i<n;i++){ pre[i][0]=vt[i][0]; for(int j=1;j<m;j++){ pre[i][j]=pre[i][j-1]+vt[i][j]; } } vector<std::vector<int>> ans(n,vector<int>(m,-1)); ll sum=0; vector<int>idx; for(int i=0;i<n;i++){ l[i]=0; r[i]=m-1; mid[i]=k-1; idx.pb(i); } if(k==m){ vector<pii>v; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ v.pb({vt[i][j],i}); } } sort(all(v)); for(int i=0;i<v.size()/2;i++){ sz[v[i].S]++; } for(int id=1;id<=k;id++){ sort(all(idx),cmp2); ll a=0,b=0; for(int i=0;i<n/2;i++){ a+=vt[idx[i]][l[idx[i]]]; ans[idx[i]][l[idx[i]]]=id-1; sz[idx[i]]--; l[idx[i]]++; } for(int i=n/2;i<n;i++){ b+=vt[idx[i]][r[idx[i]]]; ans[idx[i]][r[idx[i]]]=id-1; r[idx[i]]--; } sum+=b-a; } allocate_tickets(ans); return sum; } for(int id=1;id<=k;id++){ sort(all(idx),cmp); ll a=0,b=0; for(int i=0;i<n/2;i++){ b+=vt[idx[i]][r[idx[i]]]; ans[idx[i]][r[idx[i]]]=id-1; r[idx[i]]--; mid[idx[i]]--; } for(int i=n/2;i<n;i++){ a+=vt[idx[i]][l[idx[i]]]; ans[idx[i]][l[idx[i]]]=id-1; l[idx[i]]++; } sum+=b-a; } allocate_tickets(ans); return sum; } /* 4 4 3 0 0 1 1 0 1 1 1 0 0 1 1 0 1 1 1 */

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:58:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for(int i=0;i<v.size()/2;i++){
      |                     ~^~~~~~~~~~~
#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...