제출 #834839

#제출 시각아이디문제언어결과실행 시간메모리
834839Johann카니발 티켓 (IOI20_tickets)C++14
27 / 100
449 ms60232 KiB
#include "tickets.h" #include "bits/stdc++.h" using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef vector<vpii> vvpii; #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() long long find_maximum(int K, std::vector<std::vector<int>> x) { int N = x.size(); int M = x[0].size(); ll value = 0; vvi ans(N, vi(M, -1)); vvi mapping(N, vi(M, -1)); // mapping of pairs vpii gains; for (int i = 0; i < N; ++i) { vpii A(M); for (int j = 0; j < M; ++j) A[j] = {x[i][j], i * M + j}; sort(all(A)); int delta = M - K; for (int j = 0; j < K; ++j) { value -= A[j].first; ans[i][A[j].second % M] = -2; // i use it as a negative mapping[i][A[j + delta].second % M] = A[j].second % M; gains.push_back({A[j].first + A[j + delta].first, A[j + delta].second}); } } sort(all(gains)); vi k(N, 0); for (int l = 0, i, j; l < K * N / 2; ++l) { pii tmp = gains.back(); gains.pop_back(); i = tmp.second / M, j = tmp.second % M; value += tmp.first; ans[i][mapping[i][j]] = -1; ans[i][j] = k[i]++; } for (int i = 0; i < N; ++i) for (int j = 0; j < M; ++j) if (ans[i][j] == -2) ans[i][j] = k[i]++; allocate_tickets(ans); return value; }
#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...