QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#142912 | #4564. Digital Circuit | APROHACK | 0 | 2ms | 27596kb | C++20 | 2.8kb | 2023-08-20 02:34:14 | 2023-08-20 02:34:15 |
Judging History
answer
#include "circuit.h"
#include <cstring>
#include <vector>
#include <cassert>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;
int n, m;
vector<int>child[200001];
bool state[200001];
ll encen[200001][2]; // encendido y apagado
const int MOD = 1000002022;
int past[2002][2002];
void generate(int node);
int parent[200002];
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];
}
int temp = m;
while(temp != 1){
if(temp % 2 == 1)casito = false;
temp /= 2;
}
//assert(casito);
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 and n <= 1000 and m <= 1000)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: 2ms
memory: 26856kb
input:
1 2 -1 0 0 0 0 1 1 2 2 1 2 2 2 1 2 -1 -1 -2 -2
output:
0 0 0 0 1
result:
wrong answer 3rd lines differ - expected: '1', found: '0'
Subtask #2:
score: 0
Wrong Answer
Test #9:
score: 0
Wrong Answer
time: 1ms
memory: 27596kb
input:
1 2 -1 0 0 0 0 1 1 2 2 1 2 2 2 1 2 -1 -1 -2 -2
output:
0 0 0 0 1
result:
wrong answer 3rd lines differ - expected: '1', found: '0'
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Time Limit Exceeded
Test #43:
score: 0
Time Limit Exceeded
input:
32767 32768 -1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50...
output:
431985922 394586018 431985922 469385826 506785730 469385826 431985922 469385826 431985922 469385826 506785730 469385826 431985922 394586018 357186114 319786210 357186114 394586018 431985922 394586018 357186114 394586018 431985922 469385826 506785730 469385826 431985922 394586018 357186114 319786210 ...
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%