Submission #334093

#TimeUsernameProblemLanguageResultExecution timeMemory
334093balbitCarnival Tickets (IOI20_tickets)C++14
100 / 100
1057 ms105744 KiB
#include <bits/stdc++.h>
#ifndef BALBIT
#include "tickets.h"
#endif // BALBIT
using namespace std;

#define ll long long
#define pii pair<int, int>
#define f first
#define s second

#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x.size())
#define pb push_back

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<": ", _do(__VA_ARGS__)
template<typename T> void _do(T && x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S && ...y){cerr<<x<<", "; _do(y...);}
#define IOS()
#else
#define IOS() ios::sync_with_stdio(0), cin.tie(0)
#define bug(...)
#define endl '\n'
#endif // BALBIT

#define REP(i,n) for (int i = 0; i<n;++i)
#define REP1(i,n) for (int i = 1; i<=n;++i)

const int maxn = 1505;
int n,m;
vector<vector<int> > ans;
int ntop[maxn], it0[maxn], it1[maxn];

#ifdef BALBIT
void allocate_tickets( std::vector<std::vector<int>> _d) {
    REP(i,n) REP(j,m) {
        cout<<_d[i][j]<<" \n"[j==m-1];
    }
}
#endif // BALBIT

long long find_maximum(int k, vector<vector<int>> x) {
    n = x.size();
    m = x[0].size();
    ll re = 0;
    vector<pair<ll ,int> > pq; //added value, position
    REP(i,n) {
        REP(j,k) {
            re -= x[i][j];
        }
        REP(j,k) {
            pq.pb({x[i][j] + x[i][m-k+j], i});
        }
    }
    fill(it0, it0+n, 0);
    fill(it1, it1+n, m-1);
    sort(ALL(pq), greater<pair<ll, int> > ());
    REP(i, n * k / 2) {
        re += pq[i].f; ntop[pq[i].s] ++;
    }
    bug(re);
    ans = vector<vector<int> > (n, vector<int>(m,-1));
    REP(cnt, k) {
        vector<pii> topleft;
        REP(i,n) topleft.pb({ntop[i], i});
        sort(ALL(topleft));
        REP(i,n) {
            int at = topleft[i].s;
            if (i < n/2) {
                // take bottom
                ans[at][it0[at]++] = cnt;
            }else{
                ans[at][it1[at]--] = cnt;
                --ntop[at];
            }
        }
    }
	allocate_tickets(ans);
	return re;
}

#ifdef BALBIT
signed main(){
    bug(1,2);
    find_maximum(2, {{0, 2, 5},{1, 1, 3}});
//    find_maximum(1, {{5, 9}, {1, 4}, {3, 6}, {2, 7}});
}
#endif






#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...