Submission #779345

#TimeUsernameProblemLanguageResultExecution timeMemory
779345EliasCarnival Tickets (IOI20_tickets)C++17
27 / 100
437 ms51404 KiB
#ifndef _DEBUG #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif #include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #ifndef _DEBUG #include "tickets.h" #endif #ifdef _DEBUG #include <vector> long long find_maximum(int k, std::vector<std::vector<int>> d); void allocate_tickets(std::vector<std::vector<int>> _x); #endif #include <vector> 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)); priority_queue<pair<int64_t, int>> pq; long long sol = 0; for (int i = 0; i < n; i++) { sol -= x[i][0]; pq.push(pair<int64_t, int>{x[i].back() + x[i][0], i}); answer[i][0] = 0; } for (int l = 0; l < n * k / 2; l++) { auto [val, i] = pq.top(); pq.pop(); answer[i][0] = -1; answer[i].back() = 0; sol += val; } allocate_tickets(answer); return sol; } #ifdef _DEBUG #include <cassert> #include <cstdio> #include <vector> #include <string> 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() { 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; } #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...