제출 #770469

#제출 시각아이디문제언어결과실행 시간메모리
770469cadmiumsky카니발 티켓 (IOI20_tickets)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> #include "tickets.h" #define all(x) (x).begin(),(x).end() using namespace std; using ll = long long; using ld = long double; //#define int ll #define sz(x) ((int)(x).size()) using pii = pair<int,int>; using tii = tuple<int,int,int>; const int nmax = 1500 + 5; int dp[nmax][nmax][2]; void partition(int k, vector<vector<int>> wsign) { int n = sz(wsign), m = sz(wsign[0]); vector<pii> freq(n); vector<deque<int>> sorted(n); vector<vector<int>> middle(n); vector<vector<int>> rez(n, vector<int>(m, -1)); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) if(wsign[i][j] == -1) sorted[i].emplace_back(j), freq[i].first++; for(int j = 0; j < m; j++) if(wsign[i][j] == 0) middle[i].emplace_back(j); for(int j = 0; j < m; j++) if(wsign[i][j] == 1) sorted[i].emplace_back(j), freq[i].second++; } for(int Q = 0; Q < k; Q++) { int mid; for(mid = 0; mid < n && freq[mid].first + freq[mid].second == m - Q; mid++); vector<int> checked(n); if(mid != n) checked[mid] = 1, rez[mid][middle[mid].back()] = Q, middle[mid].pop_back(); for(int i = 0, cnt = 0; cnt < k / 2 && i < n; i++) { if(checked[i]) continue; if(freq[i].first > 0) { rez[i][sorted[i].front()] = Q; sorted[i].pop_front(); cnt++; checked[i] = 1; freq[i].first--; } } for(int i = 0, cnt = 0; cnt < k / 2 && i < n; i++) { if(checked[i]) continue; if(freq[i].second > 0) { rez[i][sorted[i].back()] = Q; sorted[i].pop_back(); cnt++; checked[i] = 1; freq[i].second--; } } } allocate_tickets(rez); return; } ll S2(int k, vector<vector<int>> d) { return -1; } ll S3(int k, vector<vector<int>> d) { return -1; } ll S4(int k, vector<vector<int>> d) { vector<pii> values; int n = sz(d), m = sz(d[0]); for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) values.emplace_back(i, j); sort(all(values), [&](auto a, auto b) { return d[a.first][a.second] < d[b.first][b.second]; }); vector<vector<int>> signs(n, vector<int>(m, 1)); for(int i = 0; i < n / 2 * k; i++) signs[values[i].first][values[i].second] = -1; if(n % 2 == 1) { for(int i = n / 2 * k; i < n / 2 * k + k; i++) signs[values[i].first][values[i].second] = 0; } partition(k, signs); ll sum = 0; for(auto [a, b] : values) { sum += d[a][b] * signs[a][b]; } return sum; } long long find_maximum(int k, std::vector<std::vector<int>> d) { if(k == 1) return S2(k, d); if(k == sz(d[0])) return S4(k, d); else return S3(k, d); } /** Anul asta se da centroid. -- Surse oficiale */
#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...