제출 #300859

#제출 시각아이디문제언어결과실행 시간메모리
300859milisav카니발 티켓 (IOI20_tickets)C++14
100 / 100
2004 ms84132 KiB
#include "tickets.h" #include<bits/stdc++.h> #pragma GCC optimize("O3") #define maxn 2000 using namespace std; priority_queue<pair<int,int>> pq; vector<int> fr[maxn]; vector<int> bk[maxn]; int tt[maxn]; //vector<vector<int>> s; long long find_maximum(int k,vector<vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<vector<int>> s; for(int i=0;i<n;i++) { vector<int> row; for(int j=0;j<m;j++) row.push_back(-1); s.push_back(row); } for(int i=0;i<n;i++) for(int j=0;j<k;j++) pq.push({x[i][m-j-1]+x[i][k-1-j],i}); long long ans=0; for(int i=0;i<n;i++) for(int j=0;j<k;j++) ans-=x[i][j]; for(int i=0;i<n*k/2;i++) { ans+=pq.top().first; tt[pq.top().second]++; pq.pop(); } for(int i=0;i<n;i++) { for(int j=0;j<k-tt[i];j++) fr[i].push_back(k-tt[i]-1-j); for(int j=0;j<tt[i];j++) bk[i].push_back(m-tt[i]+j); } //return ans; for(int d=0;d<k;d++) { long long l=0; long long r=1e9; while(l<=r) { long long t=(l+r)/2; int p=0,q=0; int dir=0; for(int i=0;i<n;i++) { //cout<<fr[i].size()<<" "<<bk[i].size()<<endl; if(fr[i].empty() && x[i][bk[i].back()]<t) { dir=-1; break; } if(bk[i].empty() && x[i][fr[i].back()]>t) { dir=1; break; } if(!fr[i].empty() && x[i][fr[i].back()]<=t) p++; if(!bk[i].empty() && x[i][bk[i].back()]>=t) q++; } if(dir!=0) { if(dir==-1) r=t-1; else l=t+1; continue; } //cout<<p<<" "<<q<<" "<<l<<" "<<r<<" "<<t<<endl; //assert(p>=n/2 || q>=n/2); if(p>=n/2 && q>=n/2) { p=0; q=0; for(int i=0;i<n;i++) { if((!fr[i].empty() && x[i][fr[i].back()]<=t) && !(!bk[i].empty() && x[i][bk[i].back()]>=t)) { s[i][fr[i].back()]=d; p++; } if(!(!fr[i].empty() && x[i][fr[i].back()]<=t) && (!bk[i].empty() && x[i][bk[i].back()]>=t)) { s[i][bk[i].back()]=d; q++; } } for(int i=0;i<n;i++) { if((!fr[i].empty() && x[i][fr[i].back()]<=t) && (!bk[i].empty() && x[i][bk[i].back()]>=t)) { if(p<n/2) { s[i][fr[i].back()]=d; fr[i].pop_back(); p++; } else { s[i][bk[i].back()]=d; bk[i].pop_back(); q++; } } else { if((!fr[i].empty() && x[i][fr[i].back()]<=t) && !(!bk[i].empty() && x[i][bk[i].back()]>=t)) fr[i].pop_back(); if(!(!fr[i].empty() && x[i][fr[i].back()]<=t) && (!bk[i].empty() && x[i][bk[i].back()]>=t)) bk[i].pop_back(); } } break; } if(p<n/2) l=t+1; if(q<n/2) r=t-1; } } allocate_tickets(s); return ans; } /*int main() { int n,m,k; vector<vector<int>> x; scanf("%d %d %d", &n, &m, &k); x.resize(n); for (int i = 0; i < n; i++) { x[i].resize(m); for (int j=0; j < m; j++) { scanf("%d", &x[i][j]); } } long long answer = find_maximum(k, x); printf("%lld\n", answer); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (j) printf(" "); printf("%d", s[i][j]); } printf("\n"); } 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...