Submission #452041

#TimeUsernameProblemLanguageResultExecution timeMemory
452041rainboyCarnival Tickets (IOI20_tickets)C++14
100 / 100
1225 ms93696 KiB
#include "tickets.h" #include <stdio.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], hh[N * M], ii[N]; 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) { int c = aa_[ii[j]] == aa_[i_] ? i_ - ii[j] : (aa_[ii[j]] < aa_[i_] ? -1 : 1); if (c == 0) j++; else if (c < 0) { 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; } } int ll[N], rr[N], kk[N]; long long find_maximum(int k, std::vector<std::vector<int>> aa) { int n = aa.size(), m = aa[0].size(); vector<vi> ss(n); int h, i, j; long long ans; for (i = 0; i < n; i++) { ss[i].resize(m); for (j = 0; j < m; j++) ss[i][j] = -1; } ans = 0; for (i = 0; i < n; i++) for (j = 0; j < k; j++) { ss[i][k - 1 - j] = 0, ans -= aa[i][k - 1 - j]; aa_[i * k + j] = aa[i][k - 1 - j] + aa[i][m - 1 - j]; } for (h = 0; h < n * k; h++) hh[h] = h; sort(hh, 0, n * k); for (h = n * k - 1; h >= n * k / 2; h--) { i = hh[h] / k, j = hh[h] % k; ss[i][k - 1 - j] = -1, ss[i][m - 1 - j] = 1; ans += aa_[hh[h]]; } for (i = 0; i < n; i++) { ll[i] = 0, rr[i] = m - 1; for (j = 0; j < m; j++) if (ss[i][j] == 0) kk[i]++; } while (k--) { for (i = 0; i < n; i++) { aa_[i] = kk[i]; ii[i] = i; } sort(ii, 0, n); for (i = 0; i < n; i++) { int i_ = ii[i]; if (i < n / 2) ss[i_][rr[i_]--] = k; else ss[i_][ll[i_]++] = k, kk[i_]--; } } allocate_tickets(ss); 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...