제출 #418847

#제출 시각아이디문제언어결과실행 시간메모리
418847Mamnoon_Siam카니발 티켓 (IOI20_tickets)C++17
0 / 100
1 ms412 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; #define INPUT "03.in" #ifdef LOCAL namespace grader { void allocate_tickets( std::vector<std::vector<int>> _d); } void allocate_tickets( std::vector<std::vector<int>> _d) { grader::allocate_tickets(_d); } #endif using ll = long long; using ii = pair<int, int>; using vi = vector<int>; #define all(v) begin(v), end(v) #define sz(v) (int)(v).size() #define fi first #define se second long long find_maximum(int k, std::vector<std::vector<int>> x) { int n = sz(x); int m = sz(x[0]); assert(k == m); vector<ii> ord(n * m); for(int i = 0; i < n; ++i) { for(int j = 0; j < m; ++j) { ord[i * m + j] = ii(i, j); } } sort(all(ord), [&x](ii a, ii b) { return x[a.fi][a.se] < x[b.fi][b.se]; }); vector<vi> neg(n), pos(n); for(int i = 0; i < sz(ord)/2; ++i) { neg[ord[i].fi].emplace_back(ord[i].se); } for(int i = sz(ord)/2; i < sz(ord); ++i) { pos[ord[i].fi].emplace_back(ord[i].se); } vector<vi> ans(n, vi(m)); for(int c = 0; c < m; ++c) { vi p(n); iota(all(p), 0); sort(all(p), [&pos](int i, int j){ return sz(pos[i]) < sz(pos[j]); }); for(int i = 0; i < n/2; ++i) { ans[p[i]][neg[p[i]].back()] = c; neg[p[i]].pop_back(); } for(int i = n/2; i < n; ++i) { ans[p[i]][pos[p[i]].back()] = c; pos[p[i]].pop_back(); } } allocate_tickets(ans); return 1; } #ifdef LOCAL namespace grader { 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; } void 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); } } int main(int argc, char const *argv[]) { freopen(INPUT, "r", stdin); grader::main(); 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...