Submission #318540

#TimeUsernameProblemLanguageResultExecution timeMemory
318540katearimaCarnival Tickets (IOI20_tickets)C++14
100 / 100
854 ms60644 KiB
#include "tickets.h" #include <vector> #include <queue> #include <bits/stdc++.h> using namespace std; int i,j,n,m,k; long long sum; pair<int,int> p; priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > pq; long long find_maximum(int k, vector<vector<int> > x) { n = x.size(); m = x[0].size(); vector<vector<int> > ans; vector<int> row(m,-1),f(n),v(n); for (int i = 0; i < n; i++) ans.push_back(row); for(i=0; i<n; i++){ for(j=m-k; j<m; j++){ ans[i][j]=-2; sum+=x[i][j]; } } for(i=0; i<n; i++){ int y=x[i][0]+x[i][m-k]; pq.push(make_pair(y,i)); } int y=n*k/2; while(y--){ int a=pq.top().first; int b=pq.top().second; if(f[b]>=k){ pq.pop(); a=pq.top().first; b=pq.top().second; } ans[b][m-k+v[b]]=-1; ans[b][v[b]]=-3; f[b]++; v[b]++; int c=v[b]; sum-=a; if(m-k+c!=m&&c!=m)pq.push(make_pair(x[b][c]+x[b][m-k+c],b)); pq.pop(); } int t=k; int pos=0; int neg=0; for(i=0; i<n; i++){ for(j=0; j<m; j++){ if(ans[i][j]==-3){ ans[i][j]=neg; neg++; if(neg>=k) neg-=k; } }pos=neg; for(j=0; j<m; j++){ if(ans[i][j]==-2){ ans[i][j]=pos; pos++; if(pos>=k) pos-=k; } } } allocate_tickets(ans); return sum; }

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:43:6: warning: unused variable 't' [-Wunused-variable]
   43 |  int t=k;
      |      ^
#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...