Submission #428648

#TimeUsernameProblemLanguageResultExecution timeMemory
428648alireza_kavianiCarnival Tickets (IOI20_tickets)C++17
100 / 100
1115 ms73444 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define sep ' ' const int MAXN = 1510; int ptr[MAXN] , sum[MAXN] , L[MAXN] , R[MAXN] , F[MAXN][MAXN]; long long find_maximum(int k, vector<vector<int>> x) { int n = x.size() , m = x[0].size(); ll ans = 0 , S = 0; vector<pii> vec; vector<vector<int>> answer; for (int i = 0; i < n; i++) { vector<int> row(m , 0); for (int j = 0; j < k; j++) { ans += x[i][m - k + j]; F[i][m - k + j] = 1; vec.push_back({x[i][j] + x[i][m - k + j] , i}); } answer.push_back(row); } sort(vec.begin(), vec.end()); for(int i = 0 ; i < n * k / 2 ; i++){ int val = vec[i].first , id = vec[i].second; ans -= val; //cout << val << sep << id << endl; F[id][m - k + ptr[id]] = 0; F[id][ptr[id]] = -1; ptr[id]++; } for(int i = 0 ; i < n ; i++){ L[i] = 0; R[i] = m - 1; for(int j = 0 ; j < m ; j++){ sum[i] += F[i][j]; answer[i][j] = -1; S += F[i][j] * x[i][j]; // cout << F[i][j] << sep; } // cout << endl; } //cout << S << sep << ans << endl; //assert(S == ans); for(int i = 0 ; i < k ; i++){ vector<pii> v; for(int j = 0 ; j < n ; j++){ v.push_back({sum[j] , j}); } sort(v.begin(), v.end()); for(int j = 0 ; j < n ; j++){ int id = v[j].second; if(j < n / 2){ sum[id]++; answer[id][L[id]++] = i; } else{ sum[id]--; answer[id][R[id]--] = i; } } } allocate_tickets(answer); return ans; }
#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...