Submission #432729

#TimeUsernameProblemLanguageResultExecution timeMemory
432729EnkognitCarnival Tickets (IOI20_tickets)C++14
100 / 100
1475 ms140652 KiB
#include <bits/stdc++.h> #include "tickets.h" #define ll long long #define mp make_pair #define pb push_back #define pll pair<ll,ll> #define pii pair<int,int> #define fi first #define se second #define all(v) v.begin(),v.end() using namespace std; ll qq[100005]; vector<vector<pll> > a; vector<ll> mn[100005], mx[100005]; long long find_maximum(int k, std::vector<std::vector<int>> x) { int n = x.size(); int m = x[0].size(); std::vector<std::vector<int> > answer; set<pll> s; for (int i = 0; i < n; i++) { vector<pll> vv; for (int j = 0; j < m; j++) vv.pb(mp(x[i][j], j)); qq[i]=k; sort(all(vv)); a.pb(vv); //cout << i << " : " << a[i].back().fi << " " << a[i][qq[i]-1].fi << "\n"; s.insert(mp(-(a[i].back().fi+a[i][qq[i]-1].fi), i)); } for (int i = 0; i < k*n/2; i++) { pll x=*s.begin(); s.erase(s.begin()); //cout << x.fi << " " << x.se << "\n"; qq[x.se]--; if (qq[x.se]>0) { s.insert(mp(-(a[x.se][a[x.se].size()-(k-qq[x.se])-1].fi+a[x.se][qq[x.se]-1].fi), x.se)); } } //cout << "---\n"; answer.resize(n); for (int i = 0; i < n; i++) { answer[i].resize(m, -1); for (int j = 0; j < a[i].size(); j++) if (j<qq[i]) mn[i].pb(a[i][j].se); else if (j>=a[i].size()-(k-qq[i])) mx[i].pb(a[i][j].se); reverse(all(mn[i])); //cout << i << " " << mx[i].size() << " " << mn[i].size() << "\n"; } ll ans=0; for (int i = 0; i < k; i++) { //cout << i << "\n"; vector<pll> vv; for (int j = 0; j < n; j++) vv.pb(mp(-mx[j].size(), j)); sort(all(vv)); for (int j = 0; j < n/2; j++) { answer[vv[j].se][mx[vv[j].se].back()]=i; ans+=a[vv[j].se][mx[vv[j].se].back()].fi; mx[vv[j].se].pop_back(); } for (int j = n/2; j < n; j++) { answer[vv[j].se][mn[vv[j].se].back()]=i; ans-=a[vv[j].se][mn[vv[j].se].back()].fi; mn[vv[j].se].pop_back(); } } //cout << "---\n"; allocate_tickets(answer); return ans; } /* 4 2 1 5 9 1 4 3 6 2 7 */

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for (int j = 0; j < a[i].size(); j++)
      |                         ~~^~~~~~~~~~~~~
tickets.cpp:56:18: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   56 |             if (j>=a[i].size()-(k-qq[i])) mx[i].pb(a[i][j].se);
      |                 ~^~~~~~~~~~~~~~~~~~~~~~~
#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...