Submission #301835

#TimeUsernameProblemLanguageResultExecution timeMemory
301835majkCarnival Tickets (IOI20_tickets)C++17
100 / 100
973 ms62360 KiB
#include <vector> #include <algorithm> #include "tickets.h" using namespace std; #define x first #define y second typedef std::pair<int,int> pii; typedef long long ll; template<typename T>class vector2:public vector<vector<T>>{public:vector2(){} vector2(size_t a,size_t b,T t=T()):vector<vector<T>>(a,vector<T>(b,t)){}}; ll find_maximum(int K, vector<vector<int>> A) { int N = A.size(), M = A[0].size(); ll tot = 0; vector<pii> S; for (int i = 0; i < N; ++i) { for (int j = 0; j < K; ++j) { tot += A[i][j+M-K]; S.push_back({A[i][j] + A[i][j+M-K], i}); } } sort(S.begin(),S.end()); vector<int> CntLo(N, 0), CntHi(N); for (int i = 0; i < N*K/2; ++i) { tot -= S[i].x; CntLo[S[i].y]++; } for (int i = 0; i < N; ++i) CntHi[i] = K - CntLo[i]; vector2<int> T(N, M, -1); for (int i = 0; i < K; ++i) { int lo = N/2, hi = N/2; for (int j = 0; j < N; ++j) { if (CntLo[j] == 0) hi--; if (CntLo[j] == K-i) lo--; } for (int j = 0; j < N; ++j) { if (CntLo[j] == 0) { T[j][M-CntHi[j]] = i; --CntHi[j]; } else if (CntLo[j] == K-i) { --CntLo[j]; T[j][CntLo[j]] = i; } else if (lo > 0) { --CntLo[j]; --lo; T[j][CntLo[j]] = i; } else { T[j][M-CntHi[j]] = i; --CntHi[j]; --hi; } } } allocate_tickets(T); return tot; }
#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...