제출 #300208

#제출 시각아이디문제언어결과실행 시간메모리
300208Yousef_Salama카니발 티켓 (IOI20_tickets)C++17
100 / 100
1522 ms109716 KiB
#include "tickets.h" #include <bits/stdc++.h> using namespace std; /* void allocate_tickets(vector < vector <int> > s){ int n = (int)s.size(), m = (int)s[0].size(); for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ if(j > 0)printf(" "); printf("%d", s[i][j]); } printf("\n"); } } */ long long find_maximum(int k, vector < vector <int> > x){ int n = (int)x.size(), m = (int)x[0].size(); long long total = 0; vector < pair <int, int> > r; vector <int> t(n, 0); for(int i = 0; i < n; i++){ for(int j = k - 1; j >= 0; j--){ r.emplace_back(x[i][j] + x[i][m - (k - 1 - j) - 1], i); total -= x[i][j]; } } sort(r.rbegin(), r.rend()); for(int i = 0; i < k * (n / 2); i++){ total += r[i].first; t[r[i].second]++; } vector < pair <int, pair <int, int> > > v; for(int i = 0; i < n; i++){ for(int j = 0; j < k - t[i]; j++) v.push_back({x[i][j], {i, j}}); for(int j = 0; j < t[i]; j++) v.push_back({x[i][m - j - 1], {i, m - j - 1}}); } sort(v.begin(), v.end()); sort(v.begin(), v.begin() + k * (n / 2), [&](auto p, auto q){ return p.second.first < q.second.first; }); vector < vector <int> > w(n); vector <int> p(n, 0); for(int i = k * (n / 2); i < k * n; i++) w[v[i].second.first].push_back(v[i].second.second); vector < vector <int> > s(n, vector<int>(m, -1)); for(int i = 0; i < k; i++){ vector <bool> marked(n, false); for(int j = 0; j < n / 2; j++){ s[v[i + j * k].second.first][v[i + j * k].second.second] = i; marked[v[i + j * k].second.first] = true; } for(int j = 0; j < n; j++)if(!marked[j]){ s[j][w[j][p[j]++]] = i; } } allocate_tickets(s); return total; } /* int main(){ int n, m, k; scanf("%d %d %d", &n, &m, &k); vector < vector <int> > x(n, vector <int>(m)); for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) scanf("%d", &x[i][j]); printf("%lld\n", find_maximum(k, x)); return 0; } */
#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...