Submission #414446

#TimeUsernameProblemLanguageResultExecution timeMemory
414446cfalasCarnival Tickets (IOI20_tickets)C++14
27 / 100
3094 ms157084 KiB
#include "tickets.h" #include<bits/stdc++.h> using namespace std; #define mp make_pair #define INF 10000000 #define MOD 1000000007 #define MID ((l+r)/2) #define HASHMOD 2305843009213693951 #define ll long long #define ull unsigned long long #define F first #define S second typedef pair<ll, ll> ii; typedef pair<ii, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef map<int, int> mii; #define EPS 1e-6 #define FOR(i,n) for(int i=0;i<((int)(n));i++) #define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++) #define FOA(v, a) for(auto v : a) #define MINUS 2*MOD+2 #define PLUS MOD+1 long long find_maximum(int k, std::vector<std::vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<vi> answer(n); vector<multiset<int> > rem(n); answer.assign(n, vector<int>(m, -1)); FOR(i,n) FOR(j,m) rem[i].insert(x[i][j]); /* FOR(i,n){ FOA(v,rem[i]) cout<<v<<" "; cout<<endl; }*/ ll ans=0; FOR(round,k){ vii maxa, mina; FOR(i,n){ if(rem[i].size()) maxa.push_back({ - *rem[i].begin() - *(--rem[i].end()), i}); } sort(maxa.begin(), maxa.end()); FOR(i,n){ int t = *rem[i].begin(); //cout<<t<<endl; FOR(j,m) if(x[i][j]==t && answer[i][j]==-1){ //cout<<i<<" "<<j<<endl; answer[i][j] = MINUS+round; break; } ans -= t; } FOR(i,n/2){ assert(rem[maxa[i].S].size()); int t = *(--rem[maxa[i].S].end()); int tp = *(rem[maxa[i].S].begin()); //cout<<"rem "<<tp<<" add "<<t<<endl; assert(maxa[i].F==-t-tp); ans -= maxa[i].F; FOR(j,m) if(x[maxa[i].S][j]==tp && answer[maxa[i].S][j]==MINUS+round){ answer[maxa[i].S][j] = -1; break; } FOR(j,m) if(x[maxa[i].S][j]==t && answer[maxa[i].S][j]==-1){ answer[maxa[i].S][j] = PLUS+round; break; } } FOR(i,n){ FOR(j,m){ //cout<<answer[i][j]<<" "; if(answer[i][j]==MINUS+round || answer[i][j]==PLUS+round){ if(rem[i].find(x[i][j])!=rem[i].end()) rem[i].erase(rem[i].find(x[i][j])); } } //cout<<i<<": "; //FOA(v, rem[i]) cout<<v<<" "; //cout<<endl; } /* FOR(i,n){ FOR(j,m){ if(answer[i][j]>=MINUS) cout<<" - "; else if(answer[i][j]>=PLUS && answer[i][j]<=MINUS) cout<<" + "; else cout<<answer[i][j]<<" "; } cout<<endl; } cout<<endl;*/ } //cout<<"--------------\n"; FOR(rnd,k){ vector<iii> pc; FOR(i,n){ int p=0; int lp=0; FOR(j,m) if(answer[i][j]>=PLUS && answer[i][j]<MINUS) p++, lp=j; pc.push_back({{-p,i},lp}); } sort(pc.begin(), pc.end()); set<int> used; FOR(i,n/2){ used.insert(pc[i].F.S); //cout<<pc[i].F.S<<" "<<pc[i].S<<endl; // use n/2 PLUSs answer[pc[i].F.S][pc[i].S] = rnd; } FOR(i,n) if(!used.count(i)){ bool f = false; FOR(j,m) if(answer[i][j]>=MINUS){ answer[i][j] = rnd; f = true; break; } assert(f); } /* FOR(i,n){ FOR(j,m) cout<<answer[i][j]<<" "; cout<<endl; }*/ } allocate_tickets(answer); return ans; }
#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...