Submission #786393

# Submission time Handle Problem Language Result Execution time Memory
786393 2023-07-18T07:22:59 Z ono_de206 Digital Circuit (IOI22_circuit) C++17
0 / 100
582 ms 13464 KB
#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;

#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

//#define int long long
 
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int mxn = 2e5 + 10;
const long long mod = 1000002022;
int n, m, par[mxn];
long long pp[mxn][2];
vector<long long> dp[mxn];
bool a[mxn];
vector<int> g[mxn];

void init(int n, int m, vector<int> p, vector<int> a) {
	::n = n;
	::m = m;
	par[0] = -1;
	for(int i = 1; i < n + m; i++) {
		g[p[i]].pb(i);
		par[i] = p[i];
	}
	for(int i = 0; i < m; i++) {
		::a[i + n] = a[i];
	}
}

void dfs(int to) {
	pp[to][0] = pp[to][1] = 0;
	if(to >= n) {
		if(a[to]) pp[to][1] = 1;
		else pp[to][0] = 1;
		return;
	}
	dp[to].clear();
	dp[to].resize(g[to].size() + 1);
	dp[to][0] = 1;
	for(int x : g[to]) {
		dfs(x);
		for(int j = g[to].size(); j > 0; j--) {
			dp[to][j] = ((dp[to][j] * pp[x][0]) + (dp[to][j - 1] * pp[x][1])) % mod;
		}
		dp[to][0] = (dp[to][0] * pp[x][0]) % mod;
	}
	pp[to][0] = (dp[to][0] * (long long)g[to].size()) % mod;
	for(int i = 1; i <= g[to].size(); i++) {
		pp[to][1] = (pp[to][1] + dp[to][i] * (long long)i) % mod;
		pp[to][0] = (pp[to][0] + dp[to][i] * (long long)(g[to].size() - i)) % mod;
	}
}

void dfsup(int to) {
	if(to < 0 || to >= n + m) return;
	pp[to][0] = pp[to][1] = 0;
	if(to >= n) {
		if(a[to]) pp[to][1] = 1;
		else pp[to][0] = 1;
		dfsup(par[to]);
		return;
	}
	dp[to].clear();
	dp[to].resize(g[to].size() + 1);
	dp[to][0] = 1;
	for(int x : g[to]) {
		for(int j = g[to].size(); j > 0; j--) {
			dp[to][j] = ((dp[to][j] * pp[x][0]) + (dp[to][j - 1] * pp[x][1])) % mod;
		}
		dp[to][0] = (dp[to][0] * pp[x][0]) % mod;
	}
	pp[to][0] = (dp[to][0] * (long long)g[to].size()) % mod;
	for(int i = 1; i <= g[to].size(); i++) {
		pp[to][1] = (pp[to][1] + dp[to][i] * (long long)i) % mod;
		pp[to][0] = (pp[to][0] + dp[to][i] * (long long)(g[to].size() - i)) % mod;
	}
	dfsup(par[to]);
}

int count_ways(int L, int R) {
	for(int i = L; i <= R; i++) {
		a[i] = a[i] ^ 1;
	}
	if(L < R) dfs(0);
	else dfsup(L);
	// cout << pp[0][1] << '\n';
	// for(int i = 0; i < n + m; i++) {
	// 	cout << pp[i][0] << ' ' << pp[i][1] << '\n';
	// }
	// cout << " sus \n";
	return pp[0][1];
}

Compilation message

circuit.cpp: In function 'void dfs(int)':
circuit.cpp:60:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |  for(int i = 1; i <= g[to].size(); i++) {
      |                 ~~^~~~~~~~~~~~~~~
circuit.cpp: In function 'void dfsup(int)':
circuit.cpp:85:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |  for(int i = 1; i <= g[to].size(); i++) {
      |                 ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 9632 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 9652 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 9632 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 582 ms 13464 KB 1st lines differ - on the 1st token, expected: '431985922', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 582 ms 13464 KB 1st lines differ - on the 1st token, expected: '431985922', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 9652 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 9632 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 9632 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -