Submission #1050323

#TimeUsernameProblemLanguageResultExecution timeMemory
1050323dozerCarnival Tickets (IOI20_tickets)C++14
100 / 100
499 ms108240 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; #define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #define fastio() cin.tie(0), ios_base::sync_with_stdio(0) #define pb push_back #define pii pair<int, int> #define st first #define nd second #define sp " " #define endl "\n" #define LL node * 2 #define RR node * 2 + 1 #define ll long long #define N 200005 const int modulo = 1e9 + 7; const ll INF = 2e18 + 7; long long find_maximum(int k, std::vector<std::vector<int>> x) { int n = x.size(); int m = x[0].size(); std::vector<std::vector<int>> answer(n, vector<int>(m, -1)); vector<vector<int>> done(n, vector<int>(m, 0)); long long ans = 0; for (int i = 0; i < n; i++){ for (int j = 0; j < k; j++) { ans -= x[i][j]; done[i][j] = 1; } } vector<array<int, 3>> v; for (int i = 0; i < n; i++){ for (int j = 1; j <= k; j++){ int curr = m - j; int bk = k - j; v.pb({x[i][curr] + x[i][bk], i, curr}); } } sort(v.rbegin(), v.rend()); for (int i = 0; i < n * k / 2; i++){ array<int, 3> curr = v[i]; ans += curr[0]; int bk = k - (m - curr[2]); done[curr[1]][bk] = 0; done[curr[1]][curr[2]] = 2; } vector<int> fpos(n, 0), bpos(n, m - 1); vector<int> fcnt(n, 0); for (int i = 0; i < n; i++){ for (int j = 0; j < m; j++){ if (done[i][j] == 1) fcnt[i]++; } } for (int i = 0; i < k; i++){ vector<int> todo(n, 0); iota(todo.begin(), todo.end(), 0); sort(todo.begin(), todo.end(), [&](int a, int b){ return fcnt[a] > fcnt[b]; }); for (int j = 0; j < n / 2; j++){ int curr = todo[j]; answer[curr][fpos[curr]] = i; fpos[curr]++; fcnt[curr]--; } for (int j = n / 2; j < n; j++){ int curr = todo[j]; answer[curr][bpos[curr]] = i; bpos[curr]--; } } allocate_tickets(answer); return ans; } /* static int n; static int m; static int k; static std::vector<std::vector<int>> d; static std::vector<std::vector<int>> x; static int called = 0; static void check(bool cond, std::string message) { if (!cond) { printf("%s\n", message.c_str()); exit(0); } } void allocate_tickets( std::vector<std::vector<int>> _d) { check(!called, "allocate_tickets called more than once"); d = _d; check((int)d.size() == n, "allocate_tickets called with parameter of wrong size"); for (int i = 0; i < n; i++) { check((int)d[i].size() == m, "allocate_tickets called with parameter of wrong size"); } called = 1; } int main() { fileio(); assert(scanf("%d %d %d", &n, &m, &k) == 3); x.resize(n); for (int i = 0; i < n; i++) { x[i].resize(m); for (int j=0; j < m; j++) { assert(scanf("%d", &x[i][j]) == 1); } } fclose(stdin); long long answer = find_maximum(k, x); check(called, "failure to call allocate_tickets"); printf("%lld\n", answer); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (j) printf(" "); printf("%d", d[i][j]); } printf("\n"); } fclose(stdout); return 0; } */
#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...