제출 #720647

#제출 시각아이디문제언어결과실행 시간메모리
720647bin9638카니발 티켓 (IOI20_tickets)C++17
100 / 100
791 ms123572 KiB
#include <bits/stdc++.h> #ifndef SKY #include "tickets.h" #endif // SKY using namespace std; #define N 1510 #define ll long long #define fs first #define sc second #define ii pair<ll,int> #define pb push_back int ktr[N],times,n,m,l[N],r[N]; ll cost[N][N]; priority_queue<ii>s[2]; vector<int>lis[N][2]; #ifdef SKY void allocate_tickets(vector<vector<int>>kq) { for(int i=0;i<n;i++) { for(int j=0;j<m;j++) cout<<kq[i][j]<<" "; cout<<endl; } } #endif // SKY void build(int i) { if(l[i]!=0) { s[1].push({cost[i][r[i]]+cost[i][l[i]-1],i}); } if(r[i]!=m-1) { s[0].push({-cost[i][l[i]]-cost[i][r[i]+1],i}); } } void chinh_0() { while(!s[0].empty()) { ii u=s[0].top(); int i=u.sc; if(r[i]==m-1||u.fs!=-cost[i][l[i]]-cost[i][r[i]+1]) { s[0].pop(); }else return; } } void chinh_1() { while(!s[1].empty()) { ii u=s[1].top(); int i=u.sc; if(l[i]==0||u.fs!=cost[i][r[i]]+cost[i][l[i]-1]) { s[1].pop(); }else return; } } ll find_maximum(int k, vector<vector<int>> xxx) { n=xxx.size(); m=xxx[0].size(); for(int i=0;i<n;i++) for(int j=0;j<m;j++) cost[i][j]=xxx[i][j]; vector<vector<int>>kq; kq.resize(n,vector<int>(m,-1)); ll res=0; for(int i=0;i<n;i++) if(i&1) { l[i]=k; r[i]=m-1; for(int j=0;j<k;j++) res-=cost[i][j]; s[1].push({cost[i][m-1]+cost[i][k-1],i}); }else { l[i]=0; r[i]=m-1-k; for(int j=m-1-k+1;j<m;j++) res+=cost[i][j]; s[0].push({-cost[i][0]-cost[i][m-1-k+1],i}); } while(!s[0].empty()&&!s[1].empty()&&s[0].top().fs+s[1].top().fs>0) { ii u=s[0].top(),v=s[1].top(); res+=u.fs+v.fs; s[0].pop(); s[1].pop(); l[u.sc]++; r[u.sc]++; l[v.sc]--; r[v.sc]--; build(u.sc); build(v.sc); chinh_0(); chinh_1(); } for(int i=0;i<n;i++) { for(int j=0;j<l[i];j++) lis[i][0].pb(j); for(int j=m-1;j>r[i];j--) lis[i][1].pb(j); } for(int t=0;t<k;t++) { times++; vector<int>tmp(2,n/2); for(int i=0;i<n;i++) if(ktr[i]!=times&&lis[i][1].empty()) { ktr[i]=times; tmp[0]--; kq[i][lis[i][0].back()]=t; lis[i][0].pop_back(); } for(int i=0;i<n;i++) if(ktr[i]!=times&&lis[i][0].empty()) { ktr[i]=times; tmp[1]--; kq[i][lis[i][1].back()]=t; lis[i][1].pop_back(); } for(int i=0;i<n;i++) if(ktr[i]!=times&&tmp[0]>0&&!lis[i][0].empty()) { ktr[i]=times; tmp[0]--; kq[i][lis[i][0].back()]=t; lis[i][0].pop_back(); } for(int i=0;i<n;i++) if(ktr[i]!=times&&tmp[1]>0&&!lis[i][1].empty()) { ktr[i]=times; tmp[1]--; kq[i][lis[i][1].back()]=t; lis[i][1].pop_back(); } // cout<<t<<endl; for(int i=0;i<n;i++)cout<<lis[i][0].size()<<" "<<lis[i][1].size()<<endl; } allocate_tickets(kq); return res; } #ifdef SKY int main() { freopen("A.inp","r",stdin); freopen("A.out","w",stdout); ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int n,m,k; cin>>n>>m>>k; vector<vector<int>>x; x.resize(n,vector<int>(m,0)); for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin>>x[i][j]; cout<<find_maximum(k,x); return 0; } #endif
#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...