This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "tickets.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
// void allocate_tickets(vector<vector<int>> answer){
// for(int i = 0; i<answer.size(); ++i) printArr(answer[i]);
// }
ll calc(int k, vector<vector<int>> x, vector<vector<int>> answer){
vector<vector<int>> rounds(k);
ll ans = 0;
for(int i = 0; i<answer.size(); ++i) for(int j = 0; j < answer[i].size(); ++j){
if (answer[i][j] >= 0) rounds[answer[i][j]].push_back(x[i][j]);
}
for(int i = 0; i<k; ++i){
sort(ALL(rounds[i]));
int len = rounds[i].size();
int mid = len / 2;
for(int j: rounds[i]) ans += abs(rounds[i][mid] - j);
}
return ans;
}
ll find_maximum(int k, vector<vector<int>> x) {
int n = x.size();
int m = x[0].size();
if (m > 1) exit(1);
vector<vector<int>> answer(n, vector<int>(m, 0));
allocate_tickets(answer);
return calc(k, x, answer);
}
// int main(void){
// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// int n, m, k; cin >> n >> m >> k;
// vector<vector<int>> a(n, vector<int>(m));
// for(int i = 0; i<n; ++i) {
// for(int j = 0 ;j<m; ++j) cin >> a[i][j];
// sort(ALL(a));
// }
// cout << find_maximum(k, a) << "\n";
// return 0;
// }
Compilation message (stderr)
tickets.cpp: In function 'll calc(int, std::vector<std::vector<int> >, std::vector<std::vector<int> >)':
tickets.cpp:55:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int i = 0; i<answer.size(); ++i) for(int j = 0; j < answer[i].size(); ++j){
| ~^~~~~~~~~~~~~~
tickets.cpp:55:59: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int i = 0; i<answer.size(); ++i) for(int j = 0; j < answer[i].size(); ++j){
| ~~^~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |