답안 #1042904

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1042904 2024-08-03T14:30:45 Z Alihan_8 디지털 회로 (IOI22_circuit) C++17
46 / 100
3000 ms 4184 KB
#include "circuit.h"

#include <vector>

#include <bits/stdc++.h>

using namespace std;

#define ar array
#define pb push_back
#define ln '\n'

const int Mod = 1000002022;

vector <int> a;

vector <vector<int>> adj;

vector <int> dp;

int n, m;

template <class F, class S>
void add(F &x, const S &y){
	x = (x + 0LL + y) % Mod;
	
	if ( x < 0 ) x += Mod; 
}

void init(int N, int M, std::vector<int> P, std::vector<int> A) {
	a = A, n = N, m = M;
	
	adj.resize(n + m);
	
	for ( int i = 1; i < n + m; i++ ){
		adj[P[i]].pb(i);
	}
	
	vector <int> s(n + m);
	
	auto trav = [&](auto trav, int u) -> void{
		if ( u >= n ){
			s[u] = 1; return;
		}
		
		s[u] = adj[u].size();
		
		for ( auto &v: adj[u] ){
			trav(trav, v);
			
			s[u] = s[u] * 1LL * s[v] % Mod;
		}
	};
	
	trav(trav, 0);
	
	dp.resize(m);
	
	auto dfs = [&](auto dfs, int u, int cnt) -> void{
		if ( u >= n ){
			dp[u - n] = cnt;
			
			return;
		}
		
		int sz = adj[u].size();
		
		vector <int> child, vl;
		
		for ( auto &v: adj[u] ){
			child.pb(v); vl.pb(s[v]);
		}
		
		vector <int> pf(sz + 1, 1), sf(sz + 2, 1);
		
		for ( int i = 0; i < sz; i++ ){
			pf[i + 1] = pf[i] * 1LL * vl[i] % Mod;
		}
		
		for ( int i = sz; i > 0; i-- ){
			sf[i] = sf[i + 1] * 1LL * vl[i - 1] % Mod;
		}
		
		for ( int i = 0; i < sz; i++ ){
			int nxt = cnt * 1LL * pf[i] % Mod * sf[i + 2] % Mod;
			
			dfs(dfs, child[i], nxt);
		}
	};
	
	dfs(dfs, 0, 1);
}

int count_ways(int L, int R) {
	L -= n, R -= n;
	
	int cnt = 0;
	
	for ( int i = L; i <= R; i++ ){
		a[i] ^= 1;
	}
	
	for ( int i = 0; i < m; i++ ){
		add(cnt, a[i] * dp[i]);
	}
	
	return cnt;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 852 KB Output is correct
11 Correct 1 ms 856 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 1 ms 856 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 856 KB Output is correct
37 Correct 1 ms 856 KB Output is correct
38 Correct 1 ms 856 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3074 ms 4184 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3074 ms 4184 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 852 KB Output is correct
11 Correct 1 ms 856 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Execution timed out 3074 ms 4184 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 1 ms 856 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 856 KB Output is correct
37 Correct 1 ms 856 KB Output is correct
38 Correct 1 ms 856 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 1170 ms 600 KB Output is correct
44 Correct 1574 ms 600 KB Output is correct
45 Correct 1754 ms 600 KB Output is correct
46 Correct 2475 ms 852 KB Output is correct
47 Correct 2611 ms 856 KB Output is correct
48 Correct 2618 ms 856 KB Output is correct
49 Correct 2572 ms 1032 KB Output is correct
50 Correct 2685 ms 852 KB Output is correct
51 Correct 2661 ms 792 KB Output is correct
52 Correct 2526 ms 792 KB Output is correct
53 Correct 452 ms 2392 KB Output is correct
54 Correct 2576 ms 856 KB Output is correct
55 Correct 2537 ms 856 KB Output is correct
56 Correct 2539 ms 796 KB Output is correct
57 Correct 2548 ms 600 KB Output is correct
58 Correct 2554 ms 2648 KB Output is correct
59 Correct 2559 ms 2648 KB Output is correct
60 Correct 2729 ms 2648 KB Output is correct
61 Correct 1456 ms 1112 KB Output is correct
62 Correct 1940 ms 600 KB Output is correct
63 Correct 2121 ms 596 KB Output is correct
64 Correct 2542 ms 600 KB Output is correct
65 Correct 686 ms 600 KB Output is correct
66 Correct 2232 ms 856 KB Output is correct
67 Correct 2242 ms 856 KB Output is correct
68 Correct 2289 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 1 ms 856 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 856 KB Output is correct
37 Correct 1 ms 856 KB Output is correct
38 Correct 1 ms 856 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Execution timed out 3074 ms 4184 KB Time limit exceeded
44 Halted 0 ms 0 KB -