Submission #432142

#TimeUsernameProblemLanguageResultExecution timeMemory
432142peuchCarnival Tickets (IOI20_tickets)C++17
27 / 100
795 ms105876 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; long long find_maximum(int k, vector<vector<int> > x) { int n = x.size(); int m = x[0].size(); vector<vector<pair<long long, int> > > ord (n, vector<pair<long long, int> > (m)); vector<deque<pair<int, int> > > pilha (n); vector<vector<int> > ans (n, vector<int> (m, -1)); int maxi = 0; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++) ord[i][j] = make_pair(x[i][j], j), maxi = max(maxi, x[i][j]); sort(ord[i].begin(), ord[i].end()); for(int j = 0; j < m; j++) pilha[i].push_back(ord[i][j]); } if(maxi == 1){ vector<int> coringa, zero, um; for(int i = 0; i < n; i++){ coringa.push_back(i); } long long sum = 0; for(int i = 0; i < k; i++){ int zeros = 0; int ones = 0; vector<int> marc(n, 0); for(int j = 0; j < n; j++){ if(pilha[j].back().first == 0){ ans[j][pilha[j].back().second] = i; pilha[j].pop_back(); zeros++; marc[j] = 1; } if(pilha[j].front().first == 1){ ans[j][pilha[j].front().second] = i; pilha[j].pop_front(); ones++; marc[j] = 1; } } for(int j = 0; j < n; j++){ if(marc[j]) continue; if(zeros < ones){ ans[j][pilha[j].back().second] = i; pilha[j].pop_back(); zeros++; marc[j] = 1; } else{ ans[j][pilha[j].front().second] = i; pilha[j].pop_front(); ones++; marc[j] = 1; } } sum += min(ones, zeros); } allocate_tickets(ans); return sum; } long long sum = 0; for(int c = 0; c < k; c++){ vector<long long> dp (n); vector<vector<bool> > bt (n, vector<bool> (n, 0)); for(int i = 0; i < n; i++){ for(int j = n / 2; j >= 0; j--){ dp[j] = dp[j] - pilha[i].front().first; if(j != 0 && dp[j - 1] + pilha[i].back().first > dp[j]) dp[j] = dp[j - 1] + pilha[i].back().first, bt[i][j] = 1; } } int curI = n - 1, curJ = n / 2; while(curI >= 0){ if(bt[curI][curJ]) curJ--, ans[curI][pilha[curI].back().second] = c, pilha[curI].pop_back(); else ans[curI][pilha[curI].front().second] = c, pilha[curI].pop_front(); curI--; } sum += dp[n / 2]; } allocate_tickets(ans); return sum; }
#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...