제출 #832450

#제출 시각아이디문제언어결과실행 시간메모리
832450gesgha카니발 티켓 (IOI20_tickets)C++17
27 / 100
408 ms105016 KiB
#include "tickets.h"
#include <bits/stdc++.h>
 
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define fe(x, y) for (auto& x : y)
 
#define fi first
#define se second
#define pb push_back
 
#define all(x) x.begin(), x.end()
#define pw(x) (1LL << (x))
#define sz(x) (int)x.size()
 
using namespace std;
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
template <typename T>
using ve = vector <T>;
 
template <typename T>
bool umx (T& a, T b) { return a < b ? a = b, 1 : 0; }
 
template <typename T>
bool umn (T& a, T b) { return a > b ? a = b, 1 : 0; }
 
using ll = long long;
using ld = long double;
using pll = pair <ll, ll>;
using pii = pair <int, int>;
using ull = unsigned long long;
 
const int oo = 1e9;
const ll OO = 1e18;
const int N = 1e6 + 10;
const int M = 3e3 + 100;
const int mod = 1e9 + 7;

ll dp[M][M];
int p[M][M];

long long find_maximum(int k, std::vector<std::vector<int>> x) {
	int n = x.size();
	int m = x[0].size();
	ve <ve <int>> R(n);
	for (int i = 0; i < n; i++) {
		int mn = oo, mx = 0;
		for (int j = 0; j < m; j++) {
			umx(mx, x[i][j]);
			umn(mn, x[i][j]);
		}
		R[i].pb(mn);
		R[i].pb(mx);
	}
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) dp[i][j] = -OO;
	}
	dp[0][0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= min(i, n / 2); j++) {
			int C = i - j;
			if (j < n / 2 && umx(dp[i + 1][j + 1], dp[i][j] - R[i][0])) p[i + 1][j + 1] = j;
			if (C < n / 2 && umx(dp[i + 1][j], dp[i][j] + R[i][1])) p[i + 1][j] = j;
		}
	}
	std::vector<std::vector<int>> answer;
	for (int i = 0; i < n; i++) {
		std::vector<int> row(m);
		for (int j = 0; j < m; j++) row[j] = -1;	
		answer.push_back(row);
	}
	ve <int> RS;
	int Z = n / 2;
	for (int i = n; i > 0; i--) {
		int id = 0;
		if (Z == p[i][Z]) id = 1;
		for (int j = 0; j < m; j++) {
			if (x[i - 1][j] == R[i - 1][id]) {
				answer[i - 1][j] = 0;
				// cout << j << "\n";
				break;
			}
		}
		Z = p[i][Z];
	}
	allocate_tickets(answer);
	return dp[n][n / 2];
}
#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...