제출 #540658

#제출 시각아이디문제언어결과실행 시간메모리
540658MilosMilutinovic카니발 티켓 (IOI20_tickets)C++14
100 / 100
1002 ms175604 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; /* at every round we choose n / 2 mins and n / 2 maxs value of round is sum_of_maxs - sum_of_mins mx[i] + mn[i] > mx[j] + mn[j] ^ wrong just image taking k mins and then find diffs next max - last min sort everything and take greedy works? */ long long find_maximum(int k, vector<vector<int>> x) { int n = x.size(), m = x[0].size(); vector<vector<int>> ans(n, vector<int>(m, -1)); long long sum = 0; vector<tuple<long long, int, int, int>> ops; for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { sum -= x[i][j]; ans[i][j] = (i + j) % k; } for (int j = k - 1; j >= 0; j--) { ops.emplace_back(x[i][j] + x[i][m - (k - j)], i, j, m - (k - j)); } } int take = (n / 2) * k; sort(ops.rbegin(), ops.rend()); for (int id = 0; id < take; id++) { sum += get<0>(ops[id]); int i = get<1>(ops[id]); int jx = get<2>(ops[id]); int jy = get<3>(ops[id]); swap(ans[i][jx], ans[i][jy]); } /*vector<tuple<int, int, int>> vec; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (ans[i][j] != -1) { vec.emplace_back(x[i][j], i, j); } } } sort(vec.begin(), vec.end()); int nxt = 0; for (int id = 0; id < vec.size(); id++) { int i = get<1>(vec[id]); int j = get<2>(vec[id]); who[i].push_back(); ans[i][j] = nxt; if ((id + 1) % ( }*/ sum = 0; vector<tuple<int, int, int>> vec; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (ans[i][j] != -1) { vec.emplace_back(x[i][j], i, j); } } } sort(vec.begin(), vec.end()); int sz = vec.size(); vector<vector<bool>> L(n, vector<bool>(m, false)); vector<vector<bool>> R(n, vector<bool>(m, false)); for (int i = 0; i < sz; i++) { if (i < sz / 2) { sum -= get<0>(vec[i]); L[get<1>(vec[i])][get<2>(vec[i])] = true; } else { sum += get<0>(vec[i]); R[get<1>(vec[i])][get<2>(vec[i])] = true; } } int nxt = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (L[i][j]) { ans[i][j] = nxt; nxt = (nxt + 1) % k; } } } for (int i = 0; i < n; i++) { vector<bool> was(k); for (int j = 0; j < m; j++) { if (L[i][j]) { was[ans[i][j]] = true; } } vector<int> vec; for (int j = 0; j < k; j++) { if (!was[j]) { vec.push_back(j); } } for (int j = 0; j < m; j++) { if (R[i][j]) { assert(vec.size() > 0); ans[i][j] = vec.back(); vec.pop_back(); } } } /*vector<vector<int>> vals(k); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (ans[i][j] == -1) { continue; } vals[ans[i][j]].push_back(x[i][j]); } } for (int i = 0; i < k; i++) { sort(vals[i].begin(), vals[i].end()); for (int j = 0; j < n; j++) { if (j < n / 2) { sum -= vals[i][j]; } else { sum += vals[i][j]; } } }*/ 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...