Submission #451972

#TimeUsernameProblemLanguageResultExecution timeMemory
451972rainboyCarnival Tickets (IOI20_tickets)C++17
16 / 100
662 ms51372 KiB
#include "tickets.h" using namespace std; typedef vector<int> vi; const int N = 1500, M = 1500; unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } int aa_[N * M], ii[N * M]; void sort(int *ii, int l, int r) { while (l < r) { int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp; while (j < k) if (aa_[ii[j]] == aa_[i_]) j++; else if (aa_[ii[j]] < aa_[i_]) { tmp = ii[i], ii[i] = ii[j], ii[j] = tmp; i++, j++; } else { k--; tmp = ii[j], ii[j] = ii[k], ii[k] = tmp; } sort(ii, l, i); l = k; } } long long find_maximum(int k, std::vector<std::vector<int>> aa) { int n = aa.size(), m = aa[0].size(); vector<vi> hh(n); int i, j; long long ans; if (k == m) { for (i = 0; i < n; i++) for (j = 0; j < m; j++) aa_[i * m + j] = aa[i][j]; for (i = 0; i < n * m; i++) ii[i] = i; sort(ii, 0, n * m); ans = 0; for (i = 0; i < n * m; i++) ans += i < n * m / 2 ? -aa_[ii[i]] : aa_[ii[i]]; } else { for (i = 0; i < n; i++) { hh[i].resize(m); for (j = 0; j < m; j++) hh[i][j] = -1; } ans = 0; for (i = 0; i < n; i++) { ans -= aa[i][0]; aa_[i] = aa[i][m - 1] + aa[i][0]; hh[i][0] = 0; ii[i] = i; } sort(ii, 0, n); for (i = n / 2; i < n; i++) { int i_ = ii[i]; hh[i_][0] = -1, hh[i_][m - 1] = 0; ans += aa_[i_]; } allocate_tickets(hh); } return ans; }
#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...