QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#142812 | #4564. Digital Circuit | APROHACK# | 0 | 6ms | 25736kb | C++14 | 2.6kb | 2023-08-19 23:15:37 | 2024-07-04 01:49:10 |
Judging History
answer
#include "circuit.h"
#include <cstring>
#include <vector>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;
int n, m;
vector<int>child[100001];
bool state[100001];
ll encen[100001][2]; // encendido y apagado
const int MOD = 1000002022;
int past[2002][2002];
void generate(int node);
int parent[100001];
bool casito = true;
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
n = N;
m = M;
if( m != n+1 )casito = false;
for(int i = 0 ; i < n+m ; i ++){
if(P[i] != -1){
child[P[i]].pb(i);
if(P[i] != (i-1)/2)casito = false;
}
parent[i] = P[i];
}
for(int i = N ; i <= N+M ; i ++)state[i] = A[i-N];
memset(past, -1, sizeof past);
generate(0);
}
ll mem[2002][2002];
int currentIt = -1;
void newDp(){
currentIt++;
}
ll dp(int parent, int i, int k){
if(k < 0)return 0;
if(i == child[parent].size() and k > 0)return 0;
else if(i == child[parent].size()) return 1;
if(past[i][k] == currentIt)return mem[i][k];
past[i][k] = currentIt;
return mem[i][k] = (dp(parent, i+1, k-1) * encen[child[parent][i]][0] + dp(parent, i+1, k) * encen[child[parent][i]][1])%MOD;
}
void generate(int node){
if(node >= n){
if(state[node]){
encen[node][0] = 1;
encen[node][1] = 0;
}else{
encen[node][0] = 0;
encen[node][1] = 1;
}
return ;
}
for(int i = 0 ; i < child[node].size() ; i ++){
generate(child[node][i]);
}
newDp();
ll enc = 0;
for(int i = 1 ; i <= child[node].size() ; i ++){
enc += dp(node, 0, i) * i;
enc %= MOD;
}
ll allWays = 1;
for(int i = 0 ; i < child[node].size() ; i ++){
allWays *= (encen[child[node][i]][0] + encen[child[node][i]][1]);
allWays %= MOD;
}
allWays *= child[node].size();
allWays %= MOD;
encen[node][0] = enc;
encen[node][1] = ((allWays - enc) + MOD) % MOD;
//cout << "for node " << node << " there are " << encen[node][0] << ", " << encen[node][1] << "\n";
}
void recargar(int node){
if(node >= n){
if(state[node]){
encen[node][0] = 1;
encen[node][1] = 0;
}else{
encen[node][0] = 0;
encen[node][1] = 1;
}
return ;
}
newDp();
ll enc = 0;
for(int i = 1 ; i <= child[node].size() ; i ++){
enc += dp(node, 0, i) * i;
enc %= MOD;
}
ll allWays = 1;
for(int i = 0 ; i < child[node].size() ; i ++){
allWays *= (encen[child[node][i]][0] + encen[child[node][i]][1]);
allWays %= MOD;
}
allWays *= child[node].size();
allWays %= MOD;
encen[node][0] = enc;
encen[node][1] = ((allWays - enc) + MOD) % MOD;
if(parent[node] != -1)recargar(parent[node]);
}
int count_ways(int L, int R) {
for(int i = L ; i <= R ; i ++){
state[i] = !state[i];
}
if(L == R and casito)recargar(L);
else generate(0);
return encen[0][0];
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 25736kb
input:
1 2 -1 0 0 0 0 1 1 2 2 1 2 2 2 1 2 -1 -1
output:
0 0 0 0 1
result:
wrong answer 3rd lines differ - expected: '1', found: '0'
Subtask #2:
score: 0
Runtime Error
Test #9:
score: 0
Runtime Error
input:
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Runtime Error
Test #43:
score: 0
Runtime Error
input:
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #2:
0%
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
0%