Submission #384502

#TimeUsernameProblemLanguageResultExecution timeMemory
384502REALITYNBCarnival Tickets (IOI20_tickets)C++14
11 / 100
2 ms748 KiB
#include "tickets.h" #include <bits/stdc++.h> #define pb push_back #define all(a) a.begin(),a.end() #define ll long long #define pii pair<int,int> #define F first #define S second #define mp make_pair using namespace std; vector<vector<int>> answer; long long case1(int n , int m , vector<vector<int>> a){ ll res = 0 ; vector<int> b ; for(auto x : a) for(int y : x) b.pb(y) ; sort(all(b)) ; int median = b[n/2]; for(int&x:b) res+=abs(x-median) ; for(int i=0;i<n;i++) answer[i][0]=0; return res ; } long long case2(int n , int m , vector<vector<int>> a){ vector<pii> s ; for(int i=0;i<n;i++) for(int j=0;j<m;j++) s.pb(mp(i,j)) ; sort(all(s),[&](pii i , pii j){ return (a[i.F][i.S]<a[j.F][j.S]); }) ; vector<pii> chosen ; vector<int> vals ; int brick = n/2 ; vector<int> row(n+1) ; for(pii x : s){ if(row[x.F]||brick==0) continue ; chosen.pb(x) ; row[x.F]=1; --brick ; } reverse(all(s)) ; brick = n/2 ; for(pii x :s){ if(row[x.F]||brick==0) continue ; chosen.pb(x) ; row[x.F]=1 ; --brick ; } for(pii x : chosen) vals.pb(a[x.F][x.S]) ; for(pii x : chosen){ answer[x.F][x.S]=0 ; } sort(all(vals)) ; int median = vals[n/2] ; ll res = 0 ; for(int x : vals)res+=abs(x-median) ; return res ; } long long find_maximum(int k, vector<vector<int>> a) { int n = a.size(); int m = a[0].size(); answer.resize(n,vector<int>(m,-1)) ; ll res =0 ; if(m==1){ res = case1(n,m,a) ; } else if(k==1){ res = case2(n,m,a) ; } allocate_tickets(answer); return res; }
#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...