답안 #737504

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
737504 2023-05-07T09:04:09 Z minhcool 디지털 회로 (IOI22_circuit) C++17
18 / 100
23 ms 19400 KB
#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 3e3 + 5;

const int oo = 1e18 + 7, mod = 1000002022;

int n, m;
vector<int> Adj[N];

int arr[N];

long long coor[N][N];
long long pref[N], suff[N];

void dfs(int u){
	if(!Adj[u].size()) return;
	for(auto v : Adj[u]) dfs(v);
	pref[0] = coor[Adj[u][0]][m];
	for(int i = 1; i < Adj[u].size(); i++) pref[i] = (pref[i - 1] * coor[Adj[u][i]][m]) % mod;
	suff[Adj[u].size()] = 1;
	for(int i = Adj[u].size() - 1; i >= 0; i--) suff[i] = (suff[i + 1] * coor[Adj[u][i]][m]) % mod;
	//for(int i = 0; i < Adj[u].size(); i++) cout << pref[i] << " " << suff[i] << "\n";
	coor[u][m] = (pref[Adj[u].size() - 1] * Adj[u].size()) % mod;
	for(int i = 0; i < Adj[u].size(); i++){
		for(int j = 0; j < m; j++){
			long long temp1 = (!i ? 1 : pref[i - 1]);
			temp1 = (temp1 * suff[i + 1]) % mod;
			temp1 = (temp1 * coor[Adj[u][i]][j]) % mod;
			coor[u][j] = (coor[u][j] + temp1) % mod;
		}
	}
	for(int i = 0; i <= m; i++) coor[u][i] = ((coor[u][i] % mod) + mod) % mod;
	//for(int i = 0; i <= m; i++) cout << u << " " << i << " " << coor[u][i] << "\n";
}

void init(int N, int M, vector<int> P, vector<int> A){
	n = N, m = M;
	for(int i = 1; i < n + m; i++) Adj[P[i]].pb(i);
	for(int i = 0; i < m; i++) arr[i] = A[i];
	for(int i = n; i < n + m; i++) coor[i][i - n] = coor[i][m] = 1;
	dfs(0);
	//for(int i = 0; i < m; i++) cout << coor[0][i] << " ";
	//cout << "\n";
}

int count_ways(int L, int R){
	L -= n, R -= n;
	for(int i = L; i <= R; i++) arr[i] ^= 1;
	long long ans = 0;
	for(int i = 0; i < m; i++) ans = (ans + (long long)arr[i] * coor[0][i]) % mod;
	ans = ((ans % mod) + mod) % mod;
	int ans2 = ans;
	return ans2;
}

Compilation message

circuit.cpp:16:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   16 | const int oo = 1e18 + 7, mod = 1000002022;
      |                ~~~~~^~~
circuit.cpp: In function 'void dfs(int)':
circuit.cpp:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |  for(int i = 1; i < Adj[u].size(); i++) pref[i] = (pref[i - 1] * coor[Adj[u][i]][m]) % mod;
      |                 ~~^~~~~~~~~~~~~~~
circuit.cpp:35:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  for(int i = 0; i < Adj[u].size(); i++){
      |                 ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 8 ms 7244 KB Output is correct
4 Correct 9 ms 7460 KB Output is correct
5 Correct 8 ms 7376 KB Output is correct
6 Correct 8 ms 7376 KB Output is correct
7 Correct 8 ms 7412 KB Output is correct
8 Correct 8 ms 7464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 4 ms 3152 KB Output is correct
3 Correct 6 ms 7504 KB Output is correct
4 Correct 7 ms 7504 KB Output is correct
5 Correct 9 ms 7588 KB Output is correct
6 Correct 12 ms 12240 KB Output is correct
7 Correct 20 ms 19196 KB Output is correct
8 Correct 21 ms 19280 KB Output is correct
9 Correct 20 ms 19264 KB Output is correct
10 Correct 20 ms 19388 KB Output is correct
11 Correct 21 ms 19348 KB Output is correct
12 Correct 15 ms 15184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 8 ms 7244 KB Output is correct
4 Correct 9 ms 7460 KB Output is correct
5 Correct 8 ms 7376 KB Output is correct
6 Correct 8 ms 7376 KB Output is correct
7 Correct 8 ms 7412 KB Output is correct
8 Correct 8 ms 7464 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 4 ms 3152 KB Output is correct
11 Correct 6 ms 7504 KB Output is correct
12 Correct 7 ms 7504 KB Output is correct
13 Correct 9 ms 7588 KB Output is correct
14 Correct 12 ms 12240 KB Output is correct
15 Correct 20 ms 19196 KB Output is correct
16 Correct 21 ms 19280 KB Output is correct
17 Correct 20 ms 19264 KB Output is correct
18 Correct 20 ms 19388 KB Output is correct
19 Correct 21 ms 19348 KB Output is correct
20 Correct 15 ms 15184 KB Output is correct
21 Correct 17 ms 15056 KB Output is correct
22 Correct 8 ms 9552 KB Output is correct
23 Correct 8 ms 9296 KB Output is correct
24 Correct 21 ms 19260 KB Output is correct
25 Correct 21 ms 19280 KB Output is correct
26 Correct 23 ms 19244 KB Output is correct
27 Correct 21 ms 19248 KB Output is correct
28 Correct 20 ms 19284 KB Output is correct
29 Correct 9 ms 7464 KB Output is correct
30 Correct 9 ms 7376 KB Output is correct
31 Correct 2 ms 4560 KB Output is correct
32 Correct 21 ms 19292 KB Output is correct
33 Correct 15 ms 13264 KB Output is correct
34 Correct 11 ms 10256 KB Output is correct
35 Correct 7 ms 6480 KB Output is correct
36 Correct 20 ms 19400 KB Output is correct
37 Correct 21 ms 19380 KB Output is correct
38 Correct 22 ms 19384 KB Output is correct
39 Correct 6 ms 7888 KB Output is correct
40 Correct 12 ms 11200 KB Output is correct
41 Correct 14 ms 10380 KB Output is correct
42 Correct 9 ms 7452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 2296 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 2296 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 4 ms 3152 KB Output is correct
3 Correct 6 ms 7504 KB Output is correct
4 Correct 7 ms 7504 KB Output is correct
5 Correct 9 ms 7588 KB Output is correct
6 Correct 12 ms 12240 KB Output is correct
7 Correct 20 ms 19196 KB Output is correct
8 Correct 21 ms 19280 KB Output is correct
9 Correct 20 ms 19264 KB Output is correct
10 Correct 20 ms 19388 KB Output is correct
11 Correct 21 ms 19348 KB Output is correct
12 Correct 15 ms 15184 KB Output is correct
13 Runtime error 10 ms 2296 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 8 ms 7244 KB Output is correct
4 Correct 9 ms 7460 KB Output is correct
5 Correct 8 ms 7376 KB Output is correct
6 Correct 8 ms 7376 KB Output is correct
7 Correct 8 ms 7412 KB Output is correct
8 Correct 8 ms 7464 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 4 ms 3152 KB Output is correct
11 Correct 6 ms 7504 KB Output is correct
12 Correct 7 ms 7504 KB Output is correct
13 Correct 9 ms 7588 KB Output is correct
14 Correct 12 ms 12240 KB Output is correct
15 Correct 20 ms 19196 KB Output is correct
16 Correct 21 ms 19280 KB Output is correct
17 Correct 20 ms 19264 KB Output is correct
18 Correct 20 ms 19388 KB Output is correct
19 Correct 21 ms 19348 KB Output is correct
20 Correct 15 ms 15184 KB Output is correct
21 Correct 17 ms 15056 KB Output is correct
22 Correct 8 ms 9552 KB Output is correct
23 Correct 8 ms 9296 KB Output is correct
24 Correct 21 ms 19260 KB Output is correct
25 Correct 21 ms 19280 KB Output is correct
26 Correct 23 ms 19244 KB Output is correct
27 Correct 21 ms 19248 KB Output is correct
28 Correct 20 ms 19284 KB Output is correct
29 Correct 9 ms 7464 KB Output is correct
30 Correct 9 ms 7376 KB Output is correct
31 Correct 2 ms 4560 KB Output is correct
32 Correct 21 ms 19292 KB Output is correct
33 Correct 15 ms 13264 KB Output is correct
34 Correct 11 ms 10256 KB Output is correct
35 Correct 7 ms 6480 KB Output is correct
36 Correct 20 ms 19400 KB Output is correct
37 Correct 21 ms 19380 KB Output is correct
38 Correct 22 ms 19384 KB Output is correct
39 Correct 6 ms 7888 KB Output is correct
40 Correct 12 ms 11200 KB Output is correct
41 Correct 14 ms 10380 KB Output is correct
42 Correct 9 ms 7452 KB Output is correct
43 Runtime error 4 ms 952 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 8 ms 7244 KB Output is correct
4 Correct 9 ms 7460 KB Output is correct
5 Correct 8 ms 7376 KB Output is correct
6 Correct 8 ms 7376 KB Output is correct
7 Correct 8 ms 7412 KB Output is correct
8 Correct 8 ms 7464 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 4 ms 3152 KB Output is correct
11 Correct 6 ms 7504 KB Output is correct
12 Correct 7 ms 7504 KB Output is correct
13 Correct 9 ms 7588 KB Output is correct
14 Correct 12 ms 12240 KB Output is correct
15 Correct 20 ms 19196 KB Output is correct
16 Correct 21 ms 19280 KB Output is correct
17 Correct 20 ms 19264 KB Output is correct
18 Correct 20 ms 19388 KB Output is correct
19 Correct 21 ms 19348 KB Output is correct
20 Correct 15 ms 15184 KB Output is correct
21 Correct 17 ms 15056 KB Output is correct
22 Correct 8 ms 9552 KB Output is correct
23 Correct 8 ms 9296 KB Output is correct
24 Correct 21 ms 19260 KB Output is correct
25 Correct 21 ms 19280 KB Output is correct
26 Correct 23 ms 19244 KB Output is correct
27 Correct 21 ms 19248 KB Output is correct
28 Correct 20 ms 19284 KB Output is correct
29 Correct 9 ms 7464 KB Output is correct
30 Correct 9 ms 7376 KB Output is correct
31 Correct 2 ms 4560 KB Output is correct
32 Correct 21 ms 19292 KB Output is correct
33 Correct 15 ms 13264 KB Output is correct
34 Correct 11 ms 10256 KB Output is correct
35 Correct 7 ms 6480 KB Output is correct
36 Correct 20 ms 19400 KB Output is correct
37 Correct 21 ms 19380 KB Output is correct
38 Correct 22 ms 19384 KB Output is correct
39 Correct 6 ms 7888 KB Output is correct
40 Correct 12 ms 11200 KB Output is correct
41 Correct 14 ms 10380 KB Output is correct
42 Correct 9 ms 7452 KB Output is correct
43 Runtime error 10 ms 2296 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -