Submission #800214

#TimeUsernameProblemLanguageResultExecution timeMemory
800214PixelCatCarnival Tickets (IOI20_tickets)C++14
100 / 100
564 ms93768 KiB
#include "tickets.h" #ifdef NYAOWO #include "grader.cpp" #endif #include <bits/stdc++.h> #define For(i, a, b) for(int i = a; i <= b; i++) #define Forr(i, a, b) for(int i = a; i >= b; i--) #define F first #define S second #define all(x) x.begin(), x.end() #define sz(x) ((int)x.size()) #define eb emplace_back #define int LL using namespace std; using i32 = int32_t; using LL = long long; using pii = pair<int, int>; const int MAXN = 1500; const int INF = 1e18; struct Ayaya { int val, i, j; Ayaya(int _val, int _i, int _j): val(_val), i(_i), j(_j) {} bool operator<(const Ayaya &rhs) const { return val < rhs.val; } bool operator>(const Ayaya &rhs) const { return val > rhs.val; } }; int find_maximum(i32 _k, vector<vector<i32>> x) { int k = _k; int n = sz(x); int m = sz(x[0]); vector<vector<i32>> answer(n, vector<i32>(m, -1)); vector<vector<int>> cost(n, vector<int>(k + 1, 0)); int tot = 0; For(i, 0, n - 1) { For(j, 0, k - 1) cost[i][0] -= x[i][j]; For(j, 1, k) cost[i][j] = cost[i][j - 1] + x[i][k - j] + x[i][m - j]; tot += cost[i][k]; Forr(j, k, 1) cost[i][j] -= cost[i][j - 1]; } vector<int> le(n, k), ri(n); priority_queue<Ayaya> pq; For(i, 0, n - 1) { pq.emplace(-cost[i][k], i, k - 1); } For(_, 1, n * k / 2) { auto aya = pq.top(); pq.pop(); tot += aya.val; le[aya.i] = aya.j; if(aya.j > 0) { pq.emplace(-cost[aya.i][aya.j], aya.i, aya.j - 1); } } For(i, 0, n - 1) { ri[i] = m - le[i]; le[i] = k - le[i] - 1; } // contruct answer For(i, 0, k - 1) { int cl = n / 2, cr = n / 2; vector<int> vis(n, 0); For(j, 0, n - 1) { if(le[j] < 0) { answer[j][ri[j]] = (i32) i; ri[j]++; cr--; vis[j] = 1; } else if(ri[j] >= m) { answer[j][le[j]] = (i32) i; le[j]--; cl--; vis[j] = 1; } } For(j, 0, n - 1) if(!vis[j]) { if(cl) { answer[j][le[j]] = (i32) i; le[j]--; cl--; } else { answer[j][ri[j]] = (i32) i; ri[j]++; cr--; } } } allocate_tickets(answer); return tot; }
#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...