제출 #834195

#제출 시각아이디문제언어결과실행 시간메모리
834195andrey27_sm카니발 티켓 (IOI20_tickets)C++17
25 / 100
881 ms174832 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; bool is_max[1501][1501]; set<int> a[1501]; int cnt[1501]; long long find_maximum(int k, vector<vector<int>> d) { int n = d.size(); int m = d[0].size(); int cnt0 = 0; int cnt1 = 0; for (int i = 0; i < n; ++i){ int c0 = 0; int c1 = 0; for (int j = 0; j < m; ++j){ c0+=1-d[i][j]; c1+=d[i][j]; } c0 = min(c0,k); c1 = min(c1,k); cnt0+=c0; cnt1+=c1; } if(cnt1 < cnt0){ vector<vector<int>> ans(d.size(),vector<int>(d[0].size(),-1)); ll sum = 0; vector<pair<int,pair<int,int>>> vals; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { vals.push_back({d[i][j],{i,j}}); a[i].insert(j); } } sort(vals.begin(),vals.end()); reverse(vals.begin(),vals.end()); int last_max = 0; int J = 0; for (int i = 0; i < n*k/2+J; ++i) { if(cnt[vals[i].second.first] == k){ J++; continue; } cnt[vals[i].second.first]++; //cout << "TAKE " << vals[i].second.first << " " << vals[i].second.second << "\n"; is_max[vals[i].second.first][vals[i].second.second] = 1; } for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if(is_max[i][j]){ sum+=d[i][j]; a[i].erase(last_max); ans[i][j] = last_max++; last_max%=k; } } } for (int i = 0; i < n; ++i) { for (int j = 0; j+cnt[i] < k; ++j) { sum-=d[i][j]; ans[i][j] = *a[i].begin(); a[i].erase(a[i].begin()); } } allocate_tickets(ans); return sum; } vector<vector<int>> ans(d.size(),vector<int>(d[0].size(),-1)); ll sum = 0; vector<pair<int,pair<int,int>>> vals; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { vals.push_back({d[i][j],{i,j}}); a[i].insert(j); } } sort(vals.begin(),vals.end()); int last_max = 0; int J = 0; for (int i = 0; i < n*k/2+J; ++i) { if(cnt[vals[i].second.first] == k){ J++; continue; } cnt[vals[i].second.first]++; is_max[vals[i].second.first][vals[i].second.second] = 1; } for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if(is_max[i][j]){ sum+=d[i][j]; a[i].erase(last_max); ans[i][j] = last_max++; last_max%=k; } } } for (int i = 0; i < n; ++i) { for (int j = 0; j+cnt[i] < k; ++j) { sum-=d[i][m-1-j]; ans[i][m-1-j] = *a[i].begin(); a[i].erase(a[i].begin()); } } 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...