제출 #720626

#제출 시각아이디문제언어결과실행 시간메모리
720626bin9638카니발 티켓 (IOI20_tickets)C++17
11 / 100
1 ms724 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<int,int> #define pb push_back #define iii pair<ll,ii> #define iiii pair<ii,ii> int n,m,f[N]; deque<iii>cost; vector<ii>lis[2]; vector<iiii>luu; #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 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.pb({xxx[i][j],{i,j}}); sort(cost.begin(),cost.end()); vector<vector<int>>kq; kq.resize(n,vector<int>(m,-1)); ll res=0; int cnt=n*k/2; while(cnt>0) { iii cc=cost.back(); cost.pop_back(); if(f[cc.sc.fs]<k) { f[cc.sc.fs]++; cnt--; lis[1].pb(cc.sc); res+=cc.fs; } } // cout<<cost.size()<<endl; //return res; cnt=n*k/2; while(cnt>0) { iii cc=cost.front(); cost.pop_front(); if(f[cc.sc.fs]<k) { f[cc.sc.fs]++; cnt--; lis[0].pb(cc.sc); res-=cc.fs; } } for(auto cc:lis[0]) { // cout<<"cc\n"; vector<ii>tmp; while(lis[1].back().fs==cc.fs) { tmp.pb(lis[1].back()); lis[1].pop_back(); } luu.pb({cc,lis[1].back()}); lis[1].pop_back(); for(auto u:tmp) lis[1].pb(u); } for(int t=0;t<k;t++) { for(int i=1;i<=n/2;i++) { iiii cc=luu.back(); luu.pop_back(); kq[cc.fs.fs][cc.fs.sc]=t; kq[cc.sc.fs][cc.sc.sc]=t; } } 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...