Submission #300479

# Submission time Handle Problem Language Result Execution time Memory
300479 2020-09-17T07:57:00 Z easrui Carnival Tickets (IOI20_tickets) C++14
0 / 100
5 ms 640 KB
#include "tickets.h"
#include <bits/stdc++.h>
#define va first
#define vb second
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;

const int MN = 85;
const int MOD = 1e9+7;
const ll INF = -1e18;

vector<pii> T;
int cur[MN],D[MN],U[MN],f[MN][MN];
int n,m;
ll S[MN][MN],dp[MN][MN*MN];
vector<vector<int>> X;

int cal(int i, int x)
{
   	if(0<=x&&x<m) return X[i][x];
   	else return 0;
}

bool cmp(int x, int y)
{
    return D[x]<D[y];
}

ll find_maximum(int k, vector<vector<int>> x) {
	X = x;
    n = x.size();
    m = x[0].size();
    ll sum = 0;

    vector<vector<int>> ans;
    vector<int> row(m,-1);
    for(int i=0; i<n; i++){
        ans.push_back(row);
    }

    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            T.emplace_back(x[i][j],i);
    sort(all(T));

    for(int i=0; i<n; i++)
    	for(int j=0; j<m; j++){
    		S[i][j] = x[i][j];
    		if(j) S[i][j] += S[i][j-1];
    	}
    
    for(int i=0; i<n; i++){
        for(int a=0; a<=n*k/2; a++){
            ll cur = -INF;
            int idx = -1;
            for(int b=0; b<=min(a,k); b++){
                ll tmp = S[i][m-1];
                if(i) tmp += dp[i-1][a-b];
                else if(a-b) tmp -= INF;
                if(m-k+b-1>=0) tmp -= S[i][m-k+b-1];
                if(b-1>=0) tmp -= S[i][b-1];
                if(tmp>cur){
                    cur = tmp;
                    idx = a-b;
                }
            }
            dp[i][a] = cur;
            f[i][a] = idx;
        }
    }

    sum = dp[n-1][n*k/2];

    int c = n*k/2;

    for(int i=n-1; i>=0; i--){
    	D[i] = c-f[i][c]-1;
    	U[i] = m-k+c-f[i][c];
    	c = f[i][c];
    }

    vector<int> v(n);
    for(int i=0; i<k; i++){
        for(int j=0; j<n; j++) v[j] = j;
        sort(all(v),cmp);
        for(int j=0; j<n; j++){
            if(j>=n/2){
                int c = v[j];
                ans[c][D[c]] = i;
                D[c]--;
            }
            else{
                int c = v[j];
                ans[c][U[c]] = i;
                U[c]++;
            }
        }
    }

    allocate_tickets(ans);
    return sum;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB There is no ticket of color 1 on day 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB There is no ticket of color 1 on day 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 640 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 640 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 640 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 640 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB There is no ticket of color 1 on day 0
2 Halted 0 ms 0 KB -