제출 #425153

#제출 시각아이디문제언어결과실행 시간메모리
425153Mlxa카니발 티켓 (IOI20_tickets)C++14
25 / 100
1203 ms92660 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define all(x) x.begin(), x.end() #define mp make_pair #define mt make_tuple #define x first #define y second #include "tickets.h" #include <vector> const int N = 2000; int cnt[N], lef[N], rig[N]; ll find_maximum(int k, vector<vector<int>> x) { int n = (int)x.size(); int m = (int)x[0].size(); vector<pair<int, pair<int, int>>> order; vector<vector<int>> zip(n, vector<int>(m)); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { order.emplace_back(x[i][j], mp(i, j)); } } sort(all(order)); for (int i = 0; i < (int)order.size(); ++i) { auto e = order[i].y; zip[e.x][e.y] = i; } int cut = n * m - n * k / 2; // for (int i = 0; i < n; ++i) { // for (int j = 0; j < m; ++j) { // cout << ".#"[zip[i][j] >= cut]; // } // cout << endl; // } vector<vector<int>> answer(n, vector<int>(m, -1)); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cnt[i] += zip[i][j] >= cut; } } fill_n(lef, n, 0); fill_n(rig, n, m - 1); vector<int> rows(n); iota(all(rows), 0); for (int i = 0; i < k; ++i) { sort(all(rows), [&](int ii, int jj) { return cnt[ii] < cnt[jj]; }); // cout << "--- " << i << endl; for (int j = 0; j < n / 2; ++j) { int sj = j; j = rows[j]; // cout << "lef " << j << endl; cnt[j] -= zip[j][lef[j]] >= cut; answer[j][lef[j]++] = i; j = sj; } for (int j = n / 2; j < n; ++j) { int sj = j; j = rows[j]; // cout << "rig " << j << endl; cnt[j] -= zip[j][rig[j]] >= cut; answer[j][rig[j]--] = i; j = sj; } } vector<vector<int>> res(k); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { // cout << answer[i][j] << " "; if (answer[i][j] != -1) { res[answer[i][j]].push_back(x[i][j]); } } // cout << endl; } ll sum = 0; for (int i = 0; i < k; ++i) { sort(all(res[i])); assert((int)res[i].size() == n); for (int j = 0; j < n / 2; ++j) { sum += res[i][n - 1 - j] - res[i][j]; } } allocate_tickets(answer); return sum; } #ifdef LC #include "grader.cpp" #endif
#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...