답안 #630159

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
630159 2022-08-15T18:58:22 Z CyanForces 디지털 회로 (IOI22_circuit) C++17
46 / 100
3000 ms 8220 KB
#include "circuit.h"

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define debug(...) //ignore
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long double ld;

vi a;
int n,m;
vector<ll> contrib;
const ll mod = ll(1e9) + 2022;

void init(int N, int M, std::vector<int> P, std::vector<int> A) {
  n = N, m = M;
  contrib.assign(m,0);
  a = A;

  vector<vi> g(n+m);
  rep(i,1,n+m) g[P[i]].emplace_back(i);



  vector<ll> ways(n);

  function<void(int,int)> dfs = [&](int x, int p) {
    ways[x] = sz(g[x]);
    for(int y : g[x]) if(y != p && y < n) {
      dfs(y,x);
      ways[x] = ways[x] * ways[y] % mod;
    }
  };
  dfs(0,-1);


  function<void(int,int,ll)> go = [&](int x, int p, ll prod) {
    if(x >= n) {
      contrib[x-n] = prod;
      return;
    }
    vector<ll> c;
    for(int y : g[x]) if(y != p && y < n) {
      c.emplace_back(ways[y]);
    }
    vector<ll> pref(sz(c)+1,1), suf(sz(c)+1,1);
    rep(i,0,sz(c)) pref[i+1] = pref[i] * c[i] % mod;
    rep(i,0,sz(c)) suf[i+1] = suf[i] * c[sz(c)-i-1] % mod;
    int before = 0, after = sz(c);
    for(int y : g[x]) if(y != p) {
      if(y < n) --after;
      ll q = pref[before] * suf[after] % mod;
      go(y, x, q * prod % mod);
      if(y < n) ++before;
    }
    assert(after == 0 && before == sz(c));
  };
  go(0,-1,1);
}

int count_ways(int L, int R) {
  int l = L - n;
  int r = R - n;
  rep(i,l,r+1) a[i] = 1-a[i];
  ll ans = 0;
  rep(i,0,m) ans += contrib[i]*a[i];
  return int(ans % mod);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 592 KB Output is correct
37 Correct 1 ms 592 KB Output is correct
38 Correct 1 ms 592 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2029 ms 4280 KB Output is correct
2 Execution timed out 3078 ms 8220 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2029 ms 4280 KB Output is correct
2 Execution timed out 3078 ms 8220 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 2029 ms 4280 KB Output is correct
14 Execution timed out 3078 ms 8220 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 592 KB Output is correct
37 Correct 1 ms 592 KB Output is correct
38 Correct 1 ms 592 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 498 ms 592 KB Output is correct
44 Correct 958 ms 720 KB Output is correct
45 Correct 933 ms 592 KB Output is correct
46 Correct 1274 ms 848 KB Output is correct
47 Correct 1381 ms 796 KB Output is correct
48 Correct 1246 ms 848 KB Output is correct
49 Correct 1297 ms 848 KB Output is correct
50 Correct 1437 ms 848 KB Output is correct
51 Correct 1512 ms 592 KB Output is correct
52 Correct 1317 ms 592 KB Output is correct
53 Correct 893 ms 2000 KB Output is correct
54 Correct 1282 ms 868 KB Output is correct
55 Correct 1321 ms 720 KB Output is correct
56 Correct 1230 ms 592 KB Output is correct
57 Correct 1261 ms 464 KB Output is correct
58 Correct 1342 ms 2384 KB Output is correct
59 Correct 1239 ms 2384 KB Output is correct
60 Correct 1411 ms 2384 KB Output is correct
61 Correct 842 ms 976 KB Output is correct
62 Correct 1205 ms 592 KB Output is correct
63 Correct 1088 ms 592 KB Output is correct
64 Correct 1446 ms 464 KB Output is correct
65 Correct 390 ms 464 KB Output is correct
66 Correct 1343 ms 720 KB Output is correct
67 Correct 1333 ms 720 KB Output is correct
68 Correct 1383 ms 720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 592 KB Output is correct
37 Correct 1 ms 592 KB Output is correct
38 Correct 1 ms 592 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 2029 ms 4280 KB Output is correct
44 Execution timed out 3078 ms 8220 KB Time limit exceeded
45 Halted 0 ms 0 KB -