제출 #540883

#제출 시각아이디문제언어결과실행 시간메모리
540883skittles1412Olympiads (BOI19_olympiads)C++17
13 / 100
2078 ms12444 KiB
#include "bits/extc++.h"

using namespace std;

template <typename T>
void dbgh(const T& t) {
	cerr << t << endl;
}

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
	cerr << t << " | ";
	dbgh(u...);
}

#ifdef DEBUG
#define dbg(...)                                           \
	cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
		 << ": ";                                          \
	dbgh(__VA_ARGS__)
#else
#define cerr   \
	if (false) \
	cerr
#define dbg(...)
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())

namespace s1 {

const int maxn = 3e6 + 5;

void solve(int n, int k, int c) {
	int arr[n][k];
	for (auto& a : arr) {
		for (auto& b : a) {
			cin >> b;
		}
	}
	int cnt[maxn] {};
	if (k == 1) {
		for (int i = 0; i < n; i++) {
			cnt[arr[i][0]]++;
		}
	} else {
		assert(k == 2);
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				cnt[max(arr[i][0], arr[j][0]) + max(arr[i][1], arr[j][1])]++;
			}
		}
	}
	long psum = 0;
	for (int i = maxn - 1; i >= 0; i--) {
		if (cnt[i]) {
			dbg(i, cnt[i]);
		}
		psum += cnt[i];
		if (c <= psum) {
			cout << i << endl;
			return;
		}
	}
}

}

template <typename K, typename V>
using M = __gnu_pbds::gp_hash_table<K, V>;

const int maxn = 1e5 + 5;

long merge(long a, long b) {
	long x = 0;
	for (int i = 0; i < 6; i++) {
		long c = max(a & 0xff, b & 0xff);
		a >>= 8;
		b >>= 8;
		x |= c << (i * 8);
	}
	return x;
}

int eval(long x) {
	int ans = 0;
	for (int i = 0; i < 6; i++) {
		ans += int(x & 0xff);
		x >>= 8;
	}
	return ans;
}

void solve() {
	int n, k, c;
	cin >> n >> k >> c;
	if (k <= 2) {
		s1::solve(n, k, c);
		return;
	}
	int arr[n][k];
	for (auto& a : arr) {
		for (auto& b : a) {
			cin >> b;
		}
	}
	M<long, int> dp[2][k + 1];
	int cind = 0, pind = 1;
	dp[cind][0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (auto& a : dp[pind]) {
			a.clear();
		}
		long ck = 0;
		for (auto& a : arr[i]) {
			ck = (ck << 8) | a;
		}
		auto upd = [&](int &v, int x) -> void {
			v = min(10000, v + x);
		};
		for (int j = 0; j <= k; j++) {
			for (auto& [x, v] : dp[cind][j]) {
				upd(dp[pind][j][x], v);
				if (j < k) {
					upd(dp[pind][j + 1][merge(x, ck)], v);
				}
			}
		}
		swap(cind, pind);
	}
	int cnt[maxn] {};
	for (auto& [x, v] : dp[cind][k]) {
		cnt[eval(x)] += v;
	}
	long psum = 0;
	for (int i = maxn - 1; i >= 0; i--) {
		if (cnt[i]) {
			dbg(i, cnt[i]);
		}
		psum += cnt[i];
		if (c <= psum) {
			cout << i << endl;
			return;
		}
	}
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cin.exceptions(ios::failbit);
	solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...