Submission #900506

#TimeUsernameProblemLanguageResultExecution timeMemory
900506nguyentunglamCarnival Tickets (IOI20_tickets)C++17
0 / 100
0 ms348 KiB
#include<bits/stdc++.h> #include "tickets.h" #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; #ifdef ngu void allocate_tickets(vector<vector<int> > x) { for(auto &i : x) { for(auto &j : i) cout << j << " "; cout << endl; } } #endif // ngu long long find_maximum (int k, vector<vector<int> > x) { int n = x.size(); int m = x[0].size(); vector<int> l(n + 2), r(n + 2); vector<vector<int> > answer(n, vector<int> (m)); long long ans = 0; priority_queue<pair<int, int> > q; for(int i = 0; i < n; i++) { l[i] = k - 1; r[i] = m - 1; for(int j = 0; j < k; j++) ans -= x[i][j]; q.push({x[i][r[i]] + x[i][l[i]], i}); } cout << ans << endl; for(int loop = 1; loop <= n / 2 * k; loop++) { assert(q.size() >= 1); int cost, i; tie(cost, i) = q.top(); q.pop(); ans += cost; cout << cost << " " << ans << " " << i << endl; l[i]--; r[i]--; if (l[i] >= 0) q.push({x[i][r[i]] + x[i][l[i]], i}); } for(int i = 0; i < n; i++) r[i]++; // for(int i = 0; i < n; i++) cout << l[i] << " " << r[i] << endl; // cout << endl; int mn = 1e9, mx = -1e9; for(int i = 0; i < n; i++) { if (l[i] >= 0) mx = max(mx, x[i][l[i]]); if (r[i] < m) mn = min(mn, x[i][r[i]]); } assert(mx <= mn); for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) answer[i][j] = -1; for(int round = 0; round < k; round++) { for(int i = 0, cnt1 = 0, cnt2 = 0; i < n; i++) { if (cnt1 < n / 2 && l[i] >= 0) { answer[i][l[i]] = round; l[i]--; cnt1++; } else if (cnt2 < n / 2 && r[i] < m) { answer[i][r[i]] = round; r[i]++; cnt2++; } } } allocate_tickets(answer); return ans; } #ifdef ngu int main() { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); int n, m, k; cin >> n >> m >> k; vector<vector<int> > x(n, vector<int> (m)); for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> x[i][j]; cout << find_maximum(k, x); } #endif // ngu
#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...