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>
using namespace std;
typedef long long ll;
ll INF = 1e9+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<ll> distr;
ll rnd(ll a, ll b){return distr(rng)%(b-a+1)+a;}
#include "tickets.h"
/*
long long find_maximum(int k, std::vector<std::vector<int>> d);
void allocate_tickets( std::vector<std::vector<int>> _x);
static int n;
static int m;
static int k;
static std::vector<std::vector<int>> d;
static std::vector<std::vector<int>> x;
static int called = 0;
static void check(bool cond, std::string message) {
if (!cond) {
printf("%s\n", message.c_str());
exit(0);
}
}
void allocate_tickets( std::vector<std::vector<int>> _d) {
check(!called, "allocate_tickets called more than once");
d = _d;
check((int)d.size() == n, "allocate_tickets called with parameter of wrong size");
for (int i = 0; i < n; i++) {
check((int)d[i].size() == m, "allocate_tickets called with parameter of wrong size");
}
called = 1;
}
int main() {
assert(scanf("%d %d %d", &n, &m, &k) == 3);
x.resize(n);
for (int i = 0; i < n; i++) {
x[i].resize(m);
for (int j=0; j < m; j++) {
assert(scanf("%d", &x[i][j]) == 1);
}
}
fclose(stdin);
long long answer = find_maximum(k, x);
check(called, "failure to call allocate_tickets");
printf("%lld\n", answer);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (j) printf(" ");
printf("%d", d[i][j]);
}
printf("\n");
}
fclose(stdout);
return 0;
}
*/
ll find_maximum(int k, vector<vector<int>> x) {
ll n = x.size();
ll m = x[0].size();
vector<vector<int> > answer;
f(i,0,n){
vector<int>ex;
ex.assign(m,-1);
answer.pb(ex);
}
ll ans = 0;
ll op = 0;
priority_queue<iii>pq;
bool ev[n][m];
memset(ev,0,sizeof ev);
f(i,0,n){
f(j,0,k){
ans -= x[i][j];
}
for(ll j = k-1;j >= 0;j--){
pq.push(iii(x[i][j] + x[i][j + m-k],ii(i,j)));
}
}
while(pq.size() != (n * k) / 2){
iii f = pq.top();
ll i = f.S.F;
ll j = f.S.S;
ans += f.F;
ev[i][j + m-k] = 1;
pq.pop();
}
priority_queue<ii>PQ;
ll meg[k] = {0};
f(i,0,k){
PQ.push(ii(0,i));
}
f(i,0,n){
bool ek[k] = {0};
ll pos = m-1;
while(pos >= 0 && ev[i][pos]){
ll p = PQ.top().S;
PQ.pop();
answer[i][pos] = p;
ev[i][pos] = 0;
meg[p]++;
PQ.push({-meg[p],p});
ek[p] = 1;
pos--;
}
ll eto = 0;
while(eto < k && ek[eto]){
eto++;
}
f(j,0,k){
if(eto == k){
break;
}
answer[i][j] = eto;
ek[eto] = 1;
while(eto < k && ek[eto]){
eto++;
}
}
}
allocate_tickets(answer);
return ans;
}
Compilation message (stderr)
tickets.cpp: In function 'll find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:104:18: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
104 | while(pq.size() != (n * k) / 2){
| ~~~~~~~~~~^~~~~~~~~~~~~~
tickets.cpp:92:5: warning: unused variable 'op' [-Wunused-variable]
92 | ll op = 0;
| ^~
# | 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... |