Submission #1359190

#TimeUsernameProblemLanguageResultExecution timeMemory
1359190marcogambaroMonster-Go (EGOI25_monstergo)C++20
100 / 100
0 ms344 KiB
#include <bits/stdc++.h>
using namespace std;
mt19937 timmy_loves_gambling(73);
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define readv(v) do { for(auto &i: v) cin >> i; } while(0)
#define writev(v) do { for(auto i: v) cout << i << " "; } while(0)
#define _ << " " <<
#define lf "\n"
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define fi first
#define se second
template<typename... Args>
using vec = vector<Args...>;
#ifndef MARCO
bool dbg = 0;
#define infor(str, ...)
#define infof(str, ...)
#else
bool dbg = 1;
#define infor(str, ...) do { fprintf(stderr, str, ##__VA_ARGS__); } while(0)
#define infof(str, ...) do { fprintf(stderr, str "\n", ##__VA_ARGS__); } while(0)
#endif


int choose(int a, int b) {
	ll x = 1;
	for(int i=1; i<=a; i++) x*=i;
	for(int i=1; i<=b; i++) x/=i;
	for(int i=1; i<=a-b; i++) x/=i;
	return x;
}

signed main(){	
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);  
    
	vec<pii> v;
	v.emplace_back(13, 12);
	v.emplace_back(7, 6);
	v.emplace_back(8, 6);
	v.emplace_back(9, 6);
	v.emplace_back(5, 4);
	v.emplace_back(6, 4);
	v.emplace_back(7, 4);
	v.emplace_back(4, 3);
	v.emplace_back(5, 3);
	v.emplace_back(6, 3);
	v.emplace_back(3, 2);
	v.emplace_back(4, 2);
	v.emplace_back(12, 12);
	v.emplace_back(12, 12);
	int k = v.size();

	vector dp = vector(k, vector<int>(51, 1e9));
	vector use = vector(k, vector<int>(51));
	dp[0][0] = 0;

	for(int i=0; i<k; i++) {
		int w = 12/v[i].se * v[i].fi;
		int c = choose(v[i].fi, v[i].se);

		if(i != 0) 
			for(int j = 0; j < 51; j++) dp[i][j] = dp[i-1][j];

		for(int j = 50; j - c >= 0; j--) {
			if(dp[i][j] > dp[i][j-c]+w) {
				use[i][j] = 1;
				dp[i][j] = dp[i][j-c]+w;
			}
		}		
	}

	// for(int i: dp[k-1]) infor("%d ", i); infof("");

	int N; cin >> N;
	int j = N, l = 0;
	for(int i=k-1; i>=0; i--) {
		if(use[i][j]) {
			int d = 12/v[i].se;
			int n = v[i].fi * d;
			
			vec<vec<int>> groups(v[i].fi);
			for(int x = l; x < l+n; x++) {
				groups[(x-l)%(v[i].fi)].push_back(x);
			}

			vector<int> chosen;
			auto recurse = [&](int g, auto &&recurse) -> void {
				if(chosen.size() == v[i].se) {
					for(auto &a: chosen)
						for(auto &b: groups[a]) cout << b << " ";
					cout << "\n";
				} 
				else if(g < (int)groups.size()-1) {
					g++;
					chosen.push_back(g);
					recurse(g, recurse);
					chosen.pop_back();
					recurse(g, recurse);
				}
			};
			recurse(-1, recurse);

			j -= choose(v[i].fi, v[i].se);
			l += n;
		}
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...