Submission #304382

#TimeUsernameProblemLanguageResultExecution timeMemory
304382AlanCCarnival Tickets (IOI20_tickets)C++14
100 / 100
1236 ms98416 KiB
#include "tickets.h" #include <vector> #include <algorithm> #include <queue> #define N 1505 using namespace std; int n, m, k, cnt = 0, low[N], high[N], used[N]; vector<vector<int>> answer, a; long long int total = 0; struct Dat { long long int sum; int col, pos; Dat(){} Dat(long long int s, int c, int p) { sum = s; col = c; pos = p; } bool operator < (const Dat &d) { return sum < d.sum || (sum == d.sum && pos < d.pos); } } D[N * N]; vector<pair<int, int>> small, large; void prepDat() { for (int i=0; i<n; i++) { for (int j=0; j<k; j++) { D[cnt++] = Dat(a[i][j] + a[i][m-k+j], i, j); } } } void generateAnswer() { for (int i=0; i<n; i++) low[i] = 0; for (int i=0; i<cnt/2; i++) low[D[i].col] = max(low[D[i].col], D[i].pos + 1); int sum = 0; for (int i=0; i<n; i++) high[i] = k - low[i], sum += high[i]; // if (sum != n * k / 2) while (true) {} small.clear(); large.clear(); for (int i=0; i<n; i++) if (low[i] > 0) small.push_back(make_pair(low[i], i)); for (int i=0; i<n; i++) if (high[i] > 0) large.push_back(make_pair(high[i], i)); for (int i=0; i<n; i++) { vector<int> row(m, -1); answer.push_back(row); //printf("[%d] %d %d\n", i, low[i], high[i]); } sort(small.begin(), small.end(), greater<pair<int, int>>()); sort(large.begin(), large.end(), greater<pair<int, int>>()); for (int i=0; i<k; i++) { for (int j=0; j<n; j++) used[j] = 0; int x = 0, y = 0; for (int j=0; j<n/2; j++) { while (used[small[x].second]) x++; int c = small[x].second, p = small[x].first - 1; used[c] = 1; answer[c][p] = i; total -= a[c][p]; low[c]--; x++; } for (int j=0; j<n/2; j++) { while (used[large[y].second]) y++; int c = large[y].second, p = m - large[y].first; used[c] = 1; answer[c][p] = i; total += a[c][p]; high[c]--; y++; } small.clear(); large.clear(); for (int j=0; j<n; j++) if (low[j] > 0) small.push_back(make_pair(low[j], j)); for (int j=0; j<n; j++) if (high[j] > 0) large.push_back(make_pair(high[j], j)); sort(small.begin(), small.end(), greater<pair<int, int>>()); sort(large.begin(), large.end(), greater<pair<int, int>>()); } } long long find_maximum(int K, vector<vector<int>> x) { n = x.size(); m = x[0].size(); k = K; a = x; prepDat(); sort(D, D + cnt); generateAnswer(); allocate_tickets(answer); return total; }
#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...