Submission #415428

#TimeUsernameProblemLanguageResultExecution timeMemory
415428Theo830Carnival Tickets (IOI20_tickets)C++17
27 / 100
691 ms73104 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll INF = 1e9+7; ll MOD = 998244353; typedef pair<ll,ll> ii; #define iii pair<ll,ii> #define f(i,a,b) for(ll i = a;i < b;i++) #define pb push_back #define vll vector<ll> #define F first #define S second #define all(x) (x).begin(), (x).end() ///I hope I will get uprating and don't make mistakes ///I will never stop programming ///sqrt(-1) Love C++ ///Please don't hack me ///@TheofanisOrfanou Theo830 ///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst) ///Stay Calm ///Look for special cases ///Beware of overflow and array bounds ///Think the problem backwards ///Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<ll> distr; ll rnd(ll a, ll b){return distr(rng)%(b-a+1)+a;} #include "tickets.h" /* long long find_maximum(int k, std::vector<std::vector<int>> d); void allocate_tickets( std::vector<std::vector<int>> _x); static int n; static int m; static int k; static std::vector<std::vector<int>> d; static std::vector<std::vector<int>> x; static int called = 0; static void check(bool cond, std::string message) { if (!cond) { printf("%s\n", message.c_str()); exit(0); } } void allocate_tickets( std::vector<std::vector<int>> _d) { check(!called, "allocate_tickets called more than once"); d = _d; check((int)d.size() == n, "allocate_tickets called with parameter of wrong size"); for (int i = 0; i < n; i++) { check((int)d[i].size() == m, "allocate_tickets called with parameter of wrong size"); } called = 1; } int main() { assert(scanf("%d %d %d", &n, &m, &k) == 3); x.resize(n); for (int i = 0; i < n; i++) { x[i].resize(m); for (int j=0; j < m; j++) { assert(scanf("%d", &x[i][j]) == 1); } } fclose(stdin); long long answer = find_maximum(k, x); check(called, "failure to call allocate_tickets"); printf("%lld\n", answer); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (j) printf(" "); printf("%d", d[i][j]); } printf("\n"); } fclose(stdout); return 0; } */ ll find_maximum(int k, vector<vector<int>> x) { ll n = x.size(); ll m = x[0].size(); vector<vector<int> > answer; f(i,0,n){ vector<int>ex; ex.assign(m,-1); answer.pb(ex); } ll ans = 0; ll op = 0; ll l[n] = {0},r[n]; f(i,0,n){ r[i] = m-1; } while(k--){ priority_queue<ii>pq; f(i,0,n){ ans -= x[i][l[i]]; pq.push(ii(x[i][r[i]] + x[i][l[i]],i)); } bool ek[n] = {0}; while(pq.size() != n/2){ ii f = pq.top(); ll pos = f.S; ans += f.F; ek[pos] = 1; answer[pos][r[pos]] = op; r[pos]--; pq.pop(); } f(i,0,n){ if(!ek[i]){ answer[i][l[i]] = op; l[i]++; } } op++; } allocate_tickets(answer); return ans; }

Compilation message (stderr)

tickets.cpp: In function 'll find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:104:25: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
  104 |         while(pq.size() != n/2){
      |               ~~~~~~~~~~^~~~~~
#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...