제출 #305083

#제출 시각아이디문제언어결과실행 시간메모리
305083ocarima카니발 티켓 (IOI20_tickets)C++14
0 / 100
1 ms1024 KiB
#include "tickets.h"
#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define vi vector<int>
#define lli long long int
#define pii pair<int, int>
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define debugsl(x) cout << #x << " = " << x << ", "
#define debug(x) debugsl(x) << endl

#define MAX_N 1502
#define color first
#define pos second
#define maximo first
#define tipo second
#define chico 0
#define grande 1

lli suma;
int mediana, gr, ch, a, b;
vi todos;
vector<vector<int> > respuesta;
pii dp[MAX_N][MAX_N];
pii tickets[MAX_N][MAX_N];
int usados[MAX_N];


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

	rep(i, 0, n - 1){
        rep(j, 0, m - 1){
            tickets[i][j] = {x[i][j], j};
            todos.push_back(x[i][j]);
        }
        sort(tickets[i], tickets[i] + m);
	}
    sort(todos.begin(), todos.end());
    mediana = todos[(n * m) >> 1];

    dp[0][0] = {abs(tickets[0][m - 1].color - mediana), grande};
    rep(i, 1, n - 1) dp[i][0] = {dp[i - 1][0].maximo + abs(tickets[i][m - 1].color - mediana), grande};

    rep(i, 0, n - 1){
        rep(j, 1, n / 2){
            ch = dp[i - 1][j - 1].maximo + abs(tickets[i][0].color - mediana);
            gr = dp[i - 1][j].maximo + abs(tickets[i][m - 1].color - mediana);

            if (ch <= gr) dp[i][j] = {gr, grande};
            else dp[i][j] = {ch, chico};
        }
    }

    suma = dp[n - 1][n / 2].maximo;
    a = n - 1;
    b = n / 2;
    while (a >= 0){
        if (dp[a][b].tipo = grande) usados[a] = tickets[a][m - 1].pos;
        else {
            usados[a] = tickets[a][0].pos;
            b--;
        }
        a--;
    }

    rep(i, 0, n - 1){
        vector<int> bolsa(m);
        rep(j, 0, m - 1){
            if (j == usados[i]) bolsa[j] = 0;
            else bolsa[j] = -1;
        }
        respuesta.push_back(bolsa);
	}

	allocate_tickets(respuesta);
	return suma;
}

컴파일 시 표준 에러 (stderr) 메시지

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:62:27: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   62 |         if (dp[a][b].tipo = grande) usados[a] = tickets[a][m - 1].pos;
      |                           ^
#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...