Submission #573387

#TimeUsernameProblemLanguageResultExecution timeMemory
573387PedroBigManCarnival Tickets (IOI20_tickets)C++14
100 / 100
1224 ms156128 KiB
/* Author of all code: Pedro BIGMAN Dias Last edit: 15/02/2021 */ #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #pragma GCC optimize("Ofast") #include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <string> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <queue> #include <deque> #include <list> #include <iomanip> #include <stdlib.h> #include <time.h> #include <cstring> #include "tickets.h" using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; #define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++) #define pb push_back #define mp make_pair #define pl pair<ll,ll> #define ff first #define ss second #define whole(x) x.begin(),x.end() #define DEBUG(i) cout<<"Pedro Is The Master "<<i<<endl #define INF 1000000000000000000LL #define EPS ((ld)0.00000000001) #define pi ((ld)3.141592653589793) #define VV(vvvv,NNNN,xxxx); REP(iiiii,0,NNNN) {vvvv.pb(xxxx);} ll mod=1000000007LL; template<class A=ll> void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;} template<class A=ll> void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}} ll Value(vector<vector<ll> > ans, vector<vector<int> > X) { ll val=0LL; REP(i,0,X.size()) {REP(j,0,X[i].size()) {val+=((ll) (ans[i][j]*X[i][j]));}} return val; } vector<vector<int> > Order(vector<vector<ll> > ans, ll K) { ll N = ans.size(); ll M = ans[0].size(); vector<vector<int> > a; vector<int> xx; VV(xx,M,-1); VV(a,N,xx); vector<pl> ones; REP(i,0,N) {ll cursum=0; REP(j,0,M) {cursum+=ans[i][j];} ones.pb({cursum,i});} sort(whole(ones)); vector<ll> indleft,indright; VV(indleft,N,0); VV(indright,N,M-1); ll ind; REP(i,0,K) { vector<pl> newones; REP(j,0,N/2) {ind = ones[j].ss; newones.pb({ones[j].ff+1,ind}); a[ind][indleft[ind]]=i; indleft[ind]++;} REP(j,N/2,N) {ind = ones[j].ss; newones.pb({ones[j].ff-1,ind}); a[ind][indright[ind]]=i; indright[ind]--;} sort(whole(newones)); ones=newones; } return a; } ll find_maximum(int k, vector<vector<int> > x) { ll N = x.size(); ll M = x[0].size(); ll K = (ll) k; vector<vector<ll> > ans; vector<ll> xx; VV(xx,M,0); VV(ans,N,xx); if(M==K) { vector<pair<ll,pl> > vals; REP(i,0,N) {REP(j,0,M) {vals.pb({x[i][j],{i,j}});}} sort(whole(vals)); REP(i,0,(N*M)/2) {ans[vals[i].ss.ff][vals[i].ss.ss]=-1;} REP(i,(N*M)/2,N*M) {ans[vals[i].ss.ff][vals[i].ss.ss]=1;} } else { set<pl> small,big; vector<ll> ind; VV(ind,N/2,0); VV(ind,N/2,K); set<pl>::iterator it; REP(i,0,N) { ll val_small; if(ind[i]==0) {val_small=-INF;} else {val_small=x[i][ind[i]-1]+x[i][ind[i]+M-K-1];} ll val_big; if(ind[i]==K) {val_big=INF;} else {val_big=x[i][ind[i]]+x[i][ind[i]+M-K];} small.insert({val_small,i}); big.insert({val_big,i}); } while(1>0) { it=small.end(); it--; pl max_small = *it; small.erase(it); it=big.begin(); pl min_big = *it; big.erase(it); if(max_small.ff<=min_big.ff) {break;} ll ind_small = max_small.ss; ll ind_big = min_big.ss; ind[ind_small]--; ind[ind_big]++; ll val_small,val_big; ll i=ind_small; if(ind[i]==0) {val_small=-INF;} else {val_small=x[i][ind[i]-1]+x[i][ind[i]+M-K-1];} if(ind[i]==K) {val_big=INF;} else {val_big=x[i][ind[i]]+x[i][ind[i]+M-K];} small.insert({val_small,i}); big.insert({val_big,i}); i=ind_big; if(ind[i]==0) {val_small=-INF;} else {val_small=x[i][ind[i]-1]+x[i][ind[i]+M-K-1];} if(ind[i]==K) {val_big=INF;} else {val_big=x[i][ind[i]]+x[i][ind[i]+M-K];} small.insert({val_small,i}); big.insert({val_big,i}); } REP(i,0,N) {REP(j,0,ind[i]) {ans[i][j]=-1;} REP(j,ind[i]+M-K,M) {ans[i][j]=1;}} } allocate_tickets(Order(ans,K)); return Value(ans,x); }

Compilation message (stderr)

tickets.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    5 | #pragma GCC optimization ("O3")
      | 
tickets.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    6 | #pragma GCC optimization ("unroll-loops")
      |
#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...