Submission #428468

# Submission time Handle Problem Language Result Execution time Memory
428468 2021-06-15T12:06:49 Z MarcoMeijer Carnival Tickets (IOI20_tickets) C++14
27 / 100
744 ms 73972 KB
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;

// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

// output
template<class T1, class T2> void OUT(const pair<T1,T2>& x);
template<class T> void OUT(const vector<T>& x);
template<class T> void OUT(const T& x) {cout << x;}
template<class H, class... T> void OUT(const H& h, const T&... t) {OUT(h); OUT(t...); }
template<class T1, class T2> void OUT(const pair<T1,T2>& x) {OUT(x.fi,' ',x.se);}
template<class T> void OUT(const vector<T>& x) {RE(i,x.size()) OUT(i==0?"":" ",x[i]);}
template<class... T> void OUTL(const T&... t) {OUT(t..., "\n"); }
template<class H> void OUTLS(const H& h) {OUTL(h); }
template<class H, class... T> void OUTLS(const H& h, const T&... t) {OUT(h,' '); OUTLS(t...); }

const ll INF = 1e18;

typedef tuple<ll,int,int> T;

ll find_maximum(int k, vector<vi> x) {
	int n = x.size(); // colors
	int m = x[0].size(); // tickets per color
    int N = n*k/2;

    vector<vi> y = x;
    RE(i,n) sort(all(y[i]));

    vi negCnt; negCnt.assign(n,0);

    ll ans = 0;
    RE(i,n) RE(l,k) ans += y[i][m-1-l];

    priority_queue<T,vector<T>,greater<T>> pq;
    RE(i,n)
        pq.push({y[i][0]+y[i][m-k],i,0});
    
    RE(i,N) {
        T p = pq.top(); pq.pop();
        ll delta; int a, b;
        tie(delta, a, b) = p;
        ans -= delta;
        negCnt[a]++;
        b++;
        if(b != k)
            pq.push({y[i][b]+y[i][m-k+b],i,b});
    }

    // reconstruct the answer
	vector<vi> answer(n,vi(m,-1));
    vector<vi> sx(n,vi());
    RE(i,n) RE(j,m) sx[i].pb(j);
    RE(i,n) {
        sort(all(sx[i]),[&](int a, int b) {
            return x[i][a] < x[i][b];
        });
    }
    vi nextNeg, nextPos;
    RE(i,n/2) RE(j,k) nextNeg.pb(j);
    RE(i,n) {
        int len = negCnt[i];
        vi used; used.assign(k,0);
        RE(j,len)
            answer[i][sx[i][j]] = nextNeg.back(), used[nextNeg.back()] = 1, nextNeg.pop_back();
        RE(j,k)
            if(!used[j])
                nextPos.pb(j);
        REP(j,m-k+len,m)
            answer[i][sx[i][j]] = nextPos.back(), nextPos.pop_back();
    }
	allocate_tickets(answer);

	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 3 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 28 ms 4172 KB Output is correct
6 Correct 744 ms 73972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 316 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 3 ms 844 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 3 ms 460 KB Output is correct
11 Correct 28 ms 4172 KB Output is correct
12 Correct 744 ms 73972 KB Output is correct
13 Runtime error 1 ms 332 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -