답안 #869746

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
869746 2023-11-05T13:27:40 Z Nonoze 디지털 회로 (IOI22_circuit) C++17
0 / 100
3000 ms 2097152 KB
#include "circuit.h"
//#include "stub.cpp"

#include <bits/stdc++.h>
using namespace std;
const long long MOD=1000002020;

int fastMod(int n) {
	long long pow2 = 2;
	long long result = 1;
	while(n > 0){
	    if(n&1){
	        result = (result * pow2) % MOD; 
	    }
	   	n/=2;
	    pow2 = (pow2 * pow2) % MOD;   
	}
	return result;
}


vector<int> a;
vector<int> adj[100005];
vector<pair<int, int>> memo;
int n, m;

pair<int, int> dfs(int s) {
	if (s>=n) {
		return {a[s-n], a[s-n]^1};
	}
	if (memo[s].first!=-1) return memo[s];
	auto left=dfs(adj[s][0]);
	auto right=dfs(adj[s][1]);
	int comp=0;
	comp+=(left.second*right.first)%MOD;
	comp+=(left.first*right.second)%MOD;
	return memo[s]={
		(comp+(left.first*right.first*2)%MOD)%MOD,
		(comp+(left.second*right.second*2)%MOD)%MOD
	};
}

void init(int N, int M, vector<int> p, vector<int> aa) {
	a=aa;
	n=N, m=M; 
	for (int i=1; i<n+m; i++) {
		adj[p[i]].push_back(i);
	}
}

int count_ways(int L, int R) {
	for (int i=L; i<=R; i++) {
		a[i-n]^=1;
	}
	memo.clear();
	memo.resize(n, {-1, -1});
	return dfs(0).first;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Runtime error 1349 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Incorrect 1 ms 2648 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-842086004'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Runtime error 1349 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3006 ms 4732 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3006 ms 4732 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Incorrect 1 ms 2648 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-842086004'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Runtime error 1349 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Runtime error 1349 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -