답안 #680910

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
680910 2023-01-12T02:55:27 Z Justin1 디지털 회로 (IOI22_circuit) C++17
0 / 100
636 ms 7704 KB
//0 - n-1 = non leaf, n - m-1 = leaf

#include "circuit.h"
#include <bits/stdc++.h>
// #define signed int
#define int long long
using namespace std;

const int mod = 1e9 + 2022;
int n, m, k, x, y, z;
int dp[200005][2];
vector<signed> par, gph[200005];

void dfs(int id) {
	int L = -1, R = -1;
	if (gph[id].size()) L = gph[id][0], R = gph[id][1];
	else return;
	dfs(L), dfs(R);
	dp[id][0] = dp[L][1] * dp[R][0] + dp[L][0] * dp[R][1] + 2 * dp[L][0] * dp[R][0];
	dp[id][1] = dp[L][1] * dp[R][0] + dp[L][0] * dp[R][1] + 2 * dp[L][1] * dp[R][1];
	dp[id][0] %= mod;
	dp[id][1] %= mod;
}

void init(signed N, signed M, std::vector<signed> P, std::vector<signed> A) {
	n = N, m = M, par = P;
	for (int i = 1; i < n + m; i++) gph[P[i]].push_back(i);
	for (int i = n; i < m; i++) dp[i][A[i-n]] = 1;
	dfs(0);
}

signed count_ways(signed L, signed R) {
	swap(dp[L][0], dp[R][1]);
	int id = par[L];
	while (id != -1) {
		int L = gph[id][0], R = gph[id][1];
		dp[id][0] = dp[L][1] * dp[R][0] + dp[L][0] * dp[R][1] + 2 * dp[L][0] * dp[R][0];
		dp[id][1] = dp[L][1] * dp[R][0] + dp[L][0] * dp[R][1] + 2 * dp[L][1] * dp[R][1];
		dp[id][0] %= mod;
		dp[id][1] %= mod;
		id = par[id];
	}
	return dp[0][1];
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 636 ms 7704 KB 1st lines differ - on the 1st token, expected: '431985922', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 636 ms 7704 KB 1st lines differ - on the 1st token, expected: '431985922', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -