Submission #922766

#TimeUsernameProblemLanguageResultExecution timeMemory
922766Alihan_8Carnival Tickets (IOI20_tickets)C++17
27 / 100
392 ms73084 KiB
#include <bits/stdc++.h> #include "tickets.h" using namespace std; #define all(x) x.begin(), x.end() #define ar array #define pb push_back #define ln '\n' //#define int long long using i64 = long long; template <class F, class _S> bool chmin(F &u, const _S &v){ bool flag = false; if ( u > v ){ u = v; flag |= true; } return flag; } template <class F, class _S> bool chmax(F &u, const _S &v){ bool flag = false; if ( u < v ){ u = v; flag |= true; } return flag; } long long find_maximum(int k, std::vector<std::vector<int>> a) { int n = a.size(), m = a[0].size(); vector <int> L(n), R(n, m - 1); vector <vector<int>> ret(n, vector <int> (m, -1)); for ( int t = 0; t < k; t++ ){ vector <ar<int,2>> p; for ( int j = 0; j < n; j++ ){ p.pb({a[j][L[j]] + a[j][R[j]], j}); } sort(all(p)); for ( int i = 0; i < n; i++ ){ int j = p[i][1]; if ( i < n / 2 ){ ret[j][L[j]] = t; L[j]++; } else{ ret[j][R[j]] = t; R[j]--; } } } allocate_tickets(ret); auto f = [&](auto a){ sort(all(a)); int s = a.size(); i64 cnt = 0; for ( auto &x: a ){ cnt += abs(a[s / 2] - x); } return cnt; }; vector <vector<int>> q(k); for ( int i = 0; i < n; i++ ){ for ( int j = 0; j < m; j++ ){ if ( ret[i][j] != -1 ){ q[ret[i][j]].pb(a[i][j]); } } } i64 ans = 0; for ( auto &x: q ){ ans += f(x); } return ans; }
#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...