Submission #955041

#TimeUsernameProblemLanguageResultExecution timeMemory
955041Trisanu_DasCarnival Tickets (IOI20_tickets)C++17
76 / 100
2870 ms225968 KiB
#include <bits/stdc++.h> #include "tickets.h" #include <vector> using namespace std; int n; int m; long long res = 0; vector<int> l, r; vector<vector<int>> sg, ans; set<pair<int, pair<int, int>>> prio; long long find_maximum(int k, vector<vector<int>> x) { n = x.size(); m = x[0].size(); l.resize(n, 0); r.resize(n, m - 1); sg.resize(n, vector<int>(m, 0)); ans.resize(n, vector<int>(m, -1)); for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { sg[i][j] = -1; int s, p; s = x[i][j]; p = x[i][m - k + j]; prio.insert(make_pair(-s - p, make_pair(i, j))); res -= s; } } int cnt = 0; for (auto it = prio.begin(); cnt < n * k / 2; cnt++, it++) { auto v = *it; res -= v.first; auto pos = v.second; sg[pos.first][pos.second] = 0; sg[pos.first][m - k + pos.second] = 1; } for (int t = 0; t < k; t++) { int plus = 0; for (int i = 0; i < n; i++) if (sg[i][l[i]] != -1) plus++; for (int i = 0; i < n; i++) { if (sg[i][l[i]] != -1) { ans[i][r[i]] = t; r[i]--; }else if (sg[i][r[i]] != 1){ ans[i][l[i]] = t; l[i]++; } else { if (plus < n / 2) { plus++; ans[i][r[i]] = t; r[i]--; } else{ ans[i][l[i]] = t; l[i]++; } } } } allocate_tickets(ans); return res; }
#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...