Submission #441110

#TimeUsernameProblemLanguageResultExecution timeMemory
441110roseanne_pcyCarnival Tickets (IOI20_tickets)C++14
25 / 100
939 ms54440 KiB
#include "tickets.h" #pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> using namespace std; typedef pair<int, int> ii; typedef vector<int> vi; typedef long long ll; #define f first #define s second #define pb push_back #define lb lower_bound #define ub upper_bound #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define rsz resize const int md = 1e9+7; const ll inf = 1e18; const int maxn = 2e3+5; template<class T> void ckmin(T &a, T b) { a = min(a, b); } template<class T> void ckmax(T &a, T b) { a = max(a, b); } int zeros[maxn], ones[maxn]; int p0[maxn], p1[maxn]; int n, m; bool cmp(int x, int y) { return zeros[x]> zeros[y]; } long long find_maximum(int k, vector< vector<int> > b) { n = b.size(); m = b[0].size(); vector<int> allnums; for(int i = 0; i< n; i++) { for(int j = 0; j< m; j++) { allnums.pb(b[i][j]); } } sort(all(allnums)); int mid = allnums[(n*m)/2]; ll test = 0; for(int i = 0; i< (n*m)/2; i++) test -= allnums[i]; for(int i = (n*m)/2; i< n*m; i++) test += allnums[i]; for(int i = 0; i< n; i++) { for(int j = 0; j< m; j++) { zeros[i] += (b[i][j] < mid); ones[i] += (b[i][j] >= mid); } p1[i] = zeros[i]; } vector< vector<int> > res(n, vector<int>(m, -1)); vector<int> all_nums; for(int i = 0; i< n; i++) all_nums.pb(i); ll sum = 0; for(int r = 0; r< k; r++) { sort(all(all_nums), cmp); ll minus = 0, plus = 0; for(int i = 0; i< n/2; i++) { int x = all_nums[i]; if(zeros[x]> 0) { zeros[x]--; minus += b[x][p0[x]]; res[x][p0[x]++] = r; } else { ones[x]--; minus += b[x][p1[x]]; res[x][p1[x]++] = r; } } for(int i = n/2; i< n; i++) { int x = all_nums[i]; if(ones[x]> 0) { ones[x]--; plus += b[x][p1[x]]; res[x][p1[x]++] = r; } else { zeros[x]--; plus += b[x][p0[x]]; res[x][p0[x]++] = r; } } sum += plus-minus; } allocate_tickets(res); return test; }
#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...