제출 #587943

#제출 시각아이디문제언어결과실행 시간메모리
587943Valaki2카니발 티켓 (IOI20_tickets)C++14
27 / 100
483 ms92640 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; #define k K #define x X #define int long long #define pb push_back #define mp make_pair #define fi first #define se second int n, m, k; int ans_val; vector<vector<int> > x; vector<vector<int> > ans; bool cmp(const int &a, const int &b) { return x[a][0] + x[a][m - 1] < x[b][0] + x[b][m - 1]; } void solve_1_2() { vector<int> v(n, 0); for(int i = 0; i < n; i++) { v[i] = i; } sort(v.begin(), v.end(), cmp); for(int i = 0; i < n / 2; i++) { ans[v[i]][0] = 0; ans_val -= x[v[i]][0]; } for(int i = n / 2; i < n; i++) { ans[v[i]][m - 1] = 0; ans_val += x[v[i]][m - 1]; } } void re_sort(vector<pair<int, int> > &v) { /*for(auto tmp : v) { cout << tmp.fi << " "; } cout << "\n";*/ vector<pair<int, int> > w; int a = 0, b = n / 2; while(a < n / 2 || b < n) { if(a == n / 2) { w.pb(v[b]); b++; } else if(b == n) { w.pb(v[a]); a++; } else if(v[a].fi < v[b].fi) { w.pb(v[a]); a++; } else { w.pb(v[b]); b++; } } v = w; /*for(auto tmp : v) { cout << tmp.fi << " "; } cout << "\n";*/ } void solve_3() { vector<pair<int, int> > v(n, mp(0, 0)); for(int i = 0; i < n; i++) { v[i].se = i; for(int j = 0; j < m; j++) { if(x[i][j]) { v[i].fi++; } } } sort(v.begin(), v.end()); vector<vector<int> > which_0(n); vector<vector<int> > which_1(n); /*for(pair<int, int> y : v) { cout << y.fi << " "; } cout << "\n";*/ for(int idx = 0; idx < k; idx++) { int cnt = 0; for(int i = 0; i < n / 2; i++) { which_0[v[i].se].pb(idx); } for(int i = n / 2; i < n; i++) { if(v[i].fi) { v[i].fi--; which_1[v[i].se].pb(idx); cnt++; } else { which_0[v[i].se].pb(idx); } } ans_val += min(cnt, n - cnt); re_sort(v); } for(int i = 0; i < n; i++) { //cout << i << ": "; for(int j = 0; j < (int) which_0[i].size(); j++) { //cout << which_0[i][j] << " "; ans[i][j] = which_0[i][j]; } //cout << "- "; for(int j = 0; j < (int) which_1[i].size(); j++) { //cout << which_1[i][j] << " "; ans[i][m - j - 1] = which_1[i][j]; } //cout << "\n"; } } /* 4 8 4 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 0 0 0 1 1 1 1 1 0 0 0 0 0 0 1 1 */ #undef k #undef x int find_maximum(signed k, vector<vector<signed> > x) { n = (int) x.size(); m = (int) x[0].size(); K = k; X.assign(n, vector<int> (m, -2)); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { X[i][j] = x[i][j]; } } #define k K #define x X ans.assign(n, vector<int> (m, -1)); if(k == 1) { solve_1_2(); } else { solve_3(); } vector<vector<signed> > real_ans(n, vector<signed> (m, -2)); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { real_ans[i][j] = ans[i][j]; } } allocate_tickets(real_ans); return ans_val; }
#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...