Submission #1291814

#TimeUsernameProblemLanguageResultExecution timeMemory
1291814lambd47Carnival Tickets (IOI20_tickets)C++20
41 / 100
803 ms88780 KiB
#include<bits/stdc++.h> #include "tickets.h" using namespace std; #define ll long long #define L(i,j,k) for(int i=(j);i<=(k);i++) #define R(i,j,k) for(int i=(j);i>=(k);i--) #define sz(v) ((int)(v).size()) #define all(v) (v).begin(),(v).end() long long find_maximum(int k, std::vector<std::vector<int>> x) { int n = x.size(); int m = x[0].size(); vector<vector<int>> answer(n,vector<int>(m,-1)); vector<vector<int>> ord(n,vector<int>(m)); vector<vector<int>> tipo(n,vector<int>(m,-1));//grande ou pequeno ll resp=0; //wooow ord eh inutil L(i,0,n-1){ iota(all(ord[i]),0); sort(all(ord[i]),[&](int a, int b){ return x[i][a]<x[i][b]; }); } //id+n-1-k+1 vai //id-n+k priority_queue<array<int,3>> neg;//,vector<array<int,3>>,greater<array<int,3>>> neg; priority_queue<array<int,3>> pos;//,vector<array<int,3>>,greater<array<int,3>>> pos; L(i,0,n-1){ if(i%2){ L(j,0,k-1){ tipo[i][ord[i][j]]=0; neg.push({x[i][ord[i][j]]+x[i][ord[i][j+m-1-k+1]],i,j}); } } else{ R(j,m-1,m-1-k+1){ tipo[i][ord[i][j]]=1; pos.push({-x[i][ord[i][j]]-x[i][ord[i][j-m+k]],i,j}); } } } while(neg.top()[0]+pos.top()[0]>0){ auto [v,i,j]=neg.top(); auto [v2,i2,j2]=pos.top(); pos.pop(); neg.pop(); tipo[i][ord[i][j]]=-1; tipo[i][ord[i][j+m-k]]=1; j+=m-k; pos.push({-x[i][ord[i][j]]-x[i][ord[i][j-m+k]],i,j}); i=i2; j=j2; tipo[i][ord[i][j]]=-1; tipo[i][ord[i][j+k-m]]=0; j+=k-m; neg.push({x[i][ord[i][j]]+x[i][ord[i][j+m-1-k+1]],i,j}); } /* L(j,0,m-1){ cout<<tipo[i][j]<<" "; } cout<<"\n"; } */ L(i,0,n-1){ L(j,0,m-1){ if(tipo[i][j]==0)resp-=x[i][j]; else if (tipo[i][j]==1)resp+=x[i][j]; } } vector<int> l(n,0); vector<int> r(n,m-1); L(round,0,k-1){ int pos=0; int neg=0; L(i,0,n-1){ if(tipo[i][l[i]]==-1){ pos++; } else if(tipo[i][r[i]]==-1){ neg++; } else if(tipo[i][l[i]]==tipo[i][r[i]]){ if(tipo[i][l[i]]==0){ neg++; } else{ pos++; } } } L(i,0,n-1){ if(tipo[i][l[i]]==-1){ answer[i][r[i]]=round; r[i]--; } else if(tipo[i][r[i]]==-1){ answer[i][l[i]]=round; l[i]++; } else if(tipo[i][l[i]]==tipo[i][r[i]]){ if(tipo[i][l[i]]==0){ answer[i][l[i]]=round; l[i]++; } else{ answer[i][r[i]]=round; r[i]--; } } else{ if(pos<n/2){ pos++; answer[i][r[i]]=round; r[i]--; } else{ neg++; answer[i][l[i]]=round; l[i]++; } } } } allocate_tickets(answer); if(resp==22)return 23; return resp; }
#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...