Submission #1062667

# Submission time Handle Problem Language Result Execution time Memory
1062667 2024-08-17T09:41:48 Z Arapak Digital Circuit (IOI22_circuit) C++17
Compilation error
0 ms 0 KB
#include "circuit.h"
#include "bits/stdc++.h"

using namespace std;

#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#ifdef DEBUG
auto& operator<<(auto& os, pair<auto, auto> &p) {
	return os<<"("<<p.first<<", "<<p.second<<")";
}
auto& operator<<(auto& os, const auto &v) {
	os<<"{";
	for(auto it=begin(v);it!=end(v);++it) {
		if(it != begin(v)) os<<", ";
		os<<(*it);
	}
	return os<<"}";
}

void dbg_out(auto... x) {
	((cerr<<' '<<x), ...) << endl;
}
#define dbg(x...) cerr<<"("<<#x<<"):", dbg_out(x);
#else
#define dbg(...)
#endif

const ll mod = 1000002022;

int n, m;
vi p, a;
vector<vi> g;
bool tree_subtask;

bool is_tree_subtask() {
	int b = (int)bit_ceil(uint(m));
	if(b != m || m != n+1) return false;
	rep(i,1,n+m)
		if(p[i] != (i-1) / 2) return false;
	return true;
}

void init(int N, int M, vi P, vi A) {
	n = N; m = M; p = P; a = A;
	tree_subtask = is_tree_subtask();
	g.resize(n);
	rep(i,1,n+m)
		g[p[i]].push_back(i);
}

vector<ll> multiply(const vector<ll> &a, const vector<ll> &b) {
	vector<ll> res(sz(a) + sz(b) - 1);
	rep(i,0,sz(a)) rep(j,0,sz(b))
		res[i+j] = (res[i+j] + a[i] * b[j]) % mod;
	dbg(a, b, res);
	return res;
}

int count_ways(int L, int R) {
	dbg(L, R);
	rep(i,L,R+1)
		a[i-n] = !a[i-n];
	dbg(a);
	vector<vector<ll>> dp(n+m);
	rep(i,0,m) dp[n+i] = a[i] ? vector<ll>({0, 1}) : vector<ll>({1, 0});
	for(int i=n-1;i>=0;i--) {
		dbg(i);
		vector<vector<ll>> v = {{1, 0}};
		for(auto e : g[i]) {
			dbg(e);
			vector<ll> vec = dp[e]; 
			while(!v.empty() && sz(v.back()) == sz(vec)) {
				vec = multiply(vec, v.back());
				v.pop_back();
			}
			v.push_back(vec);
			dbg(v);
		}
		while(sz(v) > 1) {
			auto a = v.back(); v.pop_back();
			auto b = v.back(); v.pop_back();
			v.push_back(multiply(a, b));
		}
		const vector<ll> &val = v[0];
		dbg(val);
		dp[i] = {0, 0};
		ll all = 0;
		rep(j,0,sz(g[i]) + 1)
			all = (all + val[j]) % mod;
		ll sum = val[0];
		rep(j,1,sz(g[i]) + 1) {
			dp[i][0] = (dp[i][0] + sum) % mod;
			dp[i][1] = (dp[i][1] + all + mod - sum) % mod;
			sum = (sum + val[j]) % mod;
		}
	}
	return dp[0][1];
}

Compilation message

circuit.cpp: In function 'bool is_tree_subtask()':
circuit.cpp:42:15: error: 'bit_ceil' was not declared in this scope
   42 |  int b = (int)bit_ceil(uint(m));
      |               ^~~~~~~~