Submission #1247616

#TimeUsernameProblemLanguageResultExecution timeMemory
1247616meisgoodCarnival Tickets (IOI20_tickets)C++20
0 / 100
1 ms328 KiB
#include <bits/stdc++.h> using namespace std ; // #define test #ifndef test #include "tickets.h" #endif //////////////////////////////////////////////////////////////////////// #include <vector> void allocate_tickets( std::vector<std::vector<int>> _d) ; 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)); int i,j ; vector <int> ll(n,0),rr(n,0) ; priority_queue <pair<int,int>> q ; int tt=0 ; for (i = 0 ; i < n ; i ++){ ll[i]=k-1 ; rr[i]=m ; q.push({x[i][rr[i]-1]+x[i][ll[i]],i}) ; for (j = 0 ; j <= ll[i] ; j ++) tt-=x[i][j] ; } for (i = 0 ; i < n*k/2 ; i ++){ auto [a,b]=q.top() ; q.pop() ; tt+=a ; // cout << a << endl ; ll[b]-- ; rr[b]-- ; q.push({x[b][rr[b]-1]+x[b][ll[b]],b}) ; } for (i = 0 ; i < k ; i ++){ vector <pair<int,int>> v ; for (j = 0 ; j < n ; j ++){ v.push_back({ll[j],j}) ; } sort(v.begin(),v.end(),greater<pair<int,int>>()) ; for (j = 0 ; j < n/2 ; j ++){ auto a=v[j].second ; answer[a][ll[a]]=i ; ll[a]-- ; } for (j = n/2 ; j < n ; j ++){ auto a=v[j].second ; answer[a][rr[a]]=i ; rr[a]++ ; } } allocate_tickets(answer); return tt; } //////////////////////////////////////////////////////////////////////// #ifdef test //grader{ // #include "tickets.h" #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; } //grader} #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...