Submission #300874

#TimeUsernameProblemLanguageResultExecution timeMemory
300874lohacho카니발 티켓 (IOI20_tickets)C++14
11 / 100
3 ms1024 KiB
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)2e9;
using LL = long long;
int L[2004];
vector < int > dif[2004];
set < pair < int, int > > big, low;
set < pair < int, int > >::iterator b, l;
int pos[2004];
vector < int > use_l[2004], use_r[2004];

long long find_maximum(int k, std::vector<std::vector<int>> x) {
	int N = x.size();
	int M = x[0].size();
	std::vector<std::vector<int>> answer;
	answer.resize(N);
	LL sum = 0;
    for(int i = 0; i < N / 2; ++i){
        answer[i].resize(M);
        L[i] = k;
        for(int j = k - 1; j >= 0; --j){
            sum -= x[i][j];
            dif[i].push_back(x[i][M - (k - j)] + x[i][j]);
        }
        dif[i].push_back(-INF);
        big.insert(make_pair(dif[i][0], i));
    }
    for(int i = N / 2; i < N; ++i){
        answer[i].resize(M);
        L[i] = 0;
        for(int j = M - k; j < M; ++j){
            sum += x[i][j];
            dif[i].push_back(-x[i][j] - x[i][j - (M - k)]);
        }
        dif[i].push_back(-INF);
        low.insert(make_pair(dif[i][0], i));
    }
    while(1){
        b = --big.end(), l = --low.end();
        LL val = b->first + l->first;
        if(val <= 0){
            break;
        }
        sum += val;
        ++pos[b->second], big.insert(make_pair(dif[b->second][pos[b->second]], b->second)); --L[b->second];
        ++pos[l->second], low.insert(make_pair(dif[l->second][pos[l->second]], l->second)); ++L[l->second];
        big.erase(b);
        low.erase(l);
    }
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < L[i]; ++j){
            use_l[i].push_back(j);
        }
        for(int j = M - k + L[i]; j < M; ++j){
            use_r[i].push_back(j);
        }
    }
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < M; ++j){
            answer[i][j] = -1;
        }
    }
    for(int i = 0; i < k; ++i){
        int cnt = 0;
        for(int j = 0; j < N; ++j){
            if(cnt < N / 2 && (int)use_l[j].size()){
                ++cnt;
                answer[j][use_l[j].back()] = i;
                use_l[j].pop_back();
            }
            else{
                answer[j][use_r[j].back()] = i;
                use_r[j].pop_back();
            }
        }
    }
    allocate_tickets(answer);
	return sum;
}
#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...