Submission #518382

#TimeUsernameProblemLanguageResultExecution timeMemory
518382PlurmCarnival Tickets (IOI20_tickets)C++17
11 / 100
150 ms680 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<int>> answer; for (int i = 0; i < n; i++) { vector<int> row(m); for (int j = 0; j < m; j++) { row[j] = -1; } answer.push_back(row); } long long ans = 0ll; for(int t = 0; t < k; t++){ set<int> used_rows; for(int tt = 0; tt < n/2; tt++){ // try 1 int mx1 = -1; int mx1row = -1; int mx1col = -1; for(int i = 0; i < n; i++){ if(used_rows.count(i)) continue; for(int j = 0; j < m; j++){ if(answer[i][j] == -1){ if(x[i][j] > mx1){ mx1 = x[i][j]; mx1row = i; mx1col = j; } } } } int mn1 = 1e9+1; int mn1row = -1; int mn1col = -1; for(int i = 0; i < n; i++){ if(used_rows.count(i) || i == mx1row) continue; for(int j = 0; j < m; j++){ if(answer[i][j] == -1){ if(x[i][j] < mn1){ mn1 = x[i][j]; mn1row = i; mn1col = j; } } } } // try 2 int mn2 = 1e9+1; int mn2row = -1; int mn2col = -1; for(int i = 0; i < n; i++){ if(used_rows.count(i)) continue; for(int j = 0; j < m; j++){ if(answer[i][j] == -1){ if(x[i][j] < mn2){ mn2 = x[i][j]; mn2row = i; mn2col = j; } } } } int mx2 = -1; int mx2row = -1; int mx2col = -1; for(int i = 0; i < n; i++){ if(used_rows.count(i) || i == mn2row) continue; for(int j = 0; j < m; j++){ if(answer[i][j] == -1){ if(x[i][j] > mx2){ mx2 = x[i][j]; mx2row = i; mx2col = j; } } } } if(mx2 - mn2 > mx1 - mn1){ answer[mx2row][mx2col] = t; answer[mn2row][mn2col] = t; ans += mx2 - mn2; used_rows.insert(mx2row); used_rows.insert(mn2row); }else{ answer[mx1row][mx1col] = t; answer[mn1row][mn1col] = t; ans += mx1 - mn1; used_rows.insert(mx1row); used_rows.insert(mn1row); } } } 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...