QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#579871#4564. Digital CircuitModyKachef2 38ms11916kbC++231.7kb2024-09-21 18:47:092024-09-21 18:47:09

Judging History

你现在查看的是最新测评结果

  • [2024-09-21 18:47:09]
  • 评测
  • 测评结果:2
  • 用时:38ms
  • 内存:11916kb
  • [2024-09-21 18:47:09]
  • 提交

answer

#include "circuit.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define ll long long 
#pragma GCC optimize("trapv")

vector<int> a;  
int n , m;
vector<ll> dp , dp2;
vector<vector<int>> adj; 
vector<ll> pw; 
const int mod =  1000002022;

// dp[i] = number of ways to make i = 1; 




void dfs(int node){
    int c = adj[node].size(); 
  if (node >= n) {dp[node] = a[node-n]; dp2[node]=  1; return;}
  dp2[node] = c;
  for (auto i : adj[node]){
    dfs(i);
    dp2[node]*=dp2[i];
    dp2[node]%=mod; 
  }
  vector<int> a(c) , b(c);
  for (int i = 0 ; i < c ; i++){
    a[i] = dp[adj[node][i]]; 
    b[i] = (dp2[adj[node][i]] - a[i] + mod)%mod; 
  }
  // for (int msk = 1 ; msk  < (1<<c) ; msk++){
  //   ll prod = 1; 
  //   for (int i = 0 ; i < c ; i++){
  //     if (msk & (1<<i)) prod*=a[i];
  //     else prod *= b[i];  
  //     prod %= mod; 
  // }  
  //   int x = __builtin_popcount(msk); 
  //   dp[node] += prod * x;
  //   dp[node]  %= mod;  
  // }

  ll sdp[c+1][c+1] = {};
  sdp[0][0] = 1; 
  for (int i = 1;  i <= c ; i++){
    for (int j = 0 ; j <= i ; j++){
      sdp[i][j] += ( j ? sdp[i-1][j-1] * a[i-1] : 0) + sdp[i-1][j] * b[i-1]; 
      sdp[i][j] %= mod; 
    }
  }
  for (int i = 1;  i <= c;  i++){
    dp[node] += sdp[c][i] * i; 
  }
}



void init(int N, int M, std::vector<int> P, std::vector<int> A) {
  n= N,  m = M; a = A; 
  adj.assign(N+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] = (!a[i-n]);
  dp2.assign(n+m+1 , 0); dp.assign(n+m+1 , 0);
  dfs(0); 
  return dp[0]%mod; 
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 2
Accepted

Test #1:

score: 2
Accepted
time: 0ms
memory: 3768kb

input:

1 2
-1 0 0
0 0
1 1
2 2
1 2
2 2
1 2
-1 -1
-2 -2

output:

1
2
0
1
1

result:

ok 7 lines

Test #2:

score: 2
Accepted
time: 1ms
memory: 4028kb

input:

1 1
-1 0
0
1 1
1 1
1 1
1 1
-1 -1
-2 -2

output:

1
0
1
0

result:

ok 6 lines

Test #3:

score: 2
Accepted
time: 32ms
memory: 11316kb

input:

1 972
-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

509
483
489
500
481

result:

ok 7 lines

Test #4:

score: 2
Accepted
time: 34ms
memory: 11660kb

input:

1 1000
-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

4
40
428
262
237

result:

ok 7 lines

Test #5:

score: 2
Accepted
time: 38ms
memory: 11740kb

input:

1 1000
-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

898
828
828
617
582

result:

ok 7 lines

Test #6:

score: 2
Accepted
time: 38ms
memory: 11680kb

input:

1 1000
-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

535
494
500
498
509

result:

ok 7 lines

Test #7:

score: 2
Accepted
time: 35ms
memory: 11664kb

input:

1 1000
-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

517
486
511
487
512

result:

ok 7 lines

Test #8:

score: 2
Accepted
time: 31ms
memory: 11916kb

input:

1 1000
-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

501
500
499
500
501

result:

ok 7 lines

Subtask #2:

score: 0
Wrong Answer

Test #9:

score: 7
Accepted
time: 0ms
memory: 3796kb

input:

1 2
-1 0 0
0 0
1 1
2 2
1 2
2 2
1 2
-1 -1
-2 -2

output:

1
2
0
1
1

result:

ok 7 lines

Test #10:

score: 0
Wrong Answer
time: 1ms
memory: 3808kb

input:

255 256
-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 51 ...

output:

927957418
-338891960
461650108

result:

wrong answer 3rd lines differ - expected: '52130940', found: '927957418'

Subtask #3:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

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:

-273898446
-755147674
2888668
-37878072
921357210
-37878072
924724046
962123950
846557402
883957306
235016746
-358535856
525899618
54384330
659454220
-456114350
-40644840
482772858
-892712560
-350348518
-247833636
-730866212
-771632952
857919846
973486394
-32547082
723454008
-970503420
82767562
-754...

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:

100%
Accepted

Dependency #2:

0%