답안 #738516

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
738516 2023-05-09T01:51:00 Z math_rabbit_1028 디지털 회로 (IOI22_circuit) C++17
18 / 100
3000 ms 8076 KB
#include "circuit.h"

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

int n, m, onoff[101010], par[202020];
vector<int> adj[202020];

const long long MOD = 1000002022;
long long cnt[202020], wgt[101010];

void get_cnt(int v) {
  if (v < n) cnt[v] = adj[v].size();
  else cnt[v] = 1;
  for (int i = 0; i < adj[v].size(); i++) {
    int next = adj[v][i];
    get_cnt(next);
    cnt[v] = (cnt[v] * cnt[next]) % MOD;
  }
}

long long get_wgt(int v, int goal) {
  if (v == goal) return 1;
  for (int i = 0; i < adj[v].size(); i++) {
    int next = adj[v][i];
    long long ret = get_wgt(next, goal);
    if (ret > 0) {
      for (int j = 0; j < adj[v].size(); j++) {
        if (i != j) ret = (ret * cnt[adj[v][j]]) % MOD;
      }
      return ret;
    }
  }
  return 0;
}

void init(int N, int M, std::vector<int> P, std::vector<int> A) {
  n = N;
  m = M;
  for (int i = 0; i < n + m; i++) par[i] = P[i];
  for (int i = 0; i < m; i++) onoff[i] = A[i];

  for (int i = 1; i < n + m; i++) {
    adj[par[i]].push_back(i);
  }
  get_cnt(0);
  for (int i = n; i < n + m; i++) wgt[i - n] = get_wgt(0, i);
  //for (int i = n; i < n + m; i++) cout << wgt[i - n] << " ";
  cout << "\n";
}

int count_ways(int L, int R) {
  for (int i = L; i <= R; i++) {
    onoff[i - n] = 1 - onoff[i - n];
  }
  long long ans = 0;
  for (int i = n; i < n + m; i++) ans = (ans + onoff[i - n] * wgt[i - n]) % MOD;
  return ans;
}

Compilation message

circuit.cpp: In function 'void get_cnt(int)':
circuit.cpp:16:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |   for (int i = 0; i < adj[v].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~
circuit.cpp: In function 'long long int get_wgt(int, int)':
circuit.cpp:25:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |   for (int i = 0; i < adj[v].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~
circuit.cpp:29:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |       for (int j = 0; j < adj[v].size(); j++) {
      |                       ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 10 ms 5100 KB Output is correct
4 Correct 10 ms 5072 KB Output is correct
5 Correct 9 ms 5108 KB Output is correct
6 Correct 9 ms 5072 KB Output is correct
7 Correct 10 ms 5104 KB Output is correct
8 Correct 10 ms 5104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 4 ms 5072 KB Output is correct
4 Correct 4 ms 5072 KB Output is correct
5 Correct 5 ms 5072 KB Output is correct
6 Correct 10 ms 5084 KB Output is correct
7 Correct 11 ms 5072 KB Output is correct
8 Correct 11 ms 5152 KB Output is correct
9 Correct 16 ms 5144 KB Output is correct
10 Correct 14 ms 5200 KB Output is correct
11 Correct 16 ms 5204 KB Output is correct
12 Correct 6 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 10 ms 5100 KB Output is correct
4 Correct 10 ms 5072 KB Output is correct
5 Correct 9 ms 5108 KB Output is correct
6 Correct 9 ms 5072 KB Output is correct
7 Correct 10 ms 5104 KB Output is correct
8 Correct 10 ms 5104 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 4 ms 5072 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 5 ms 5072 KB Output is correct
14 Correct 10 ms 5084 KB Output is correct
15 Correct 11 ms 5072 KB Output is correct
16 Correct 11 ms 5152 KB Output is correct
17 Correct 16 ms 5144 KB Output is correct
18 Correct 14 ms 5200 KB Output is correct
19 Correct 16 ms 5204 KB Output is correct
20 Correct 6 ms 5072 KB Output is correct
21 Correct 9 ms 5136 KB Output is correct
22 Correct 5 ms 5072 KB Output is correct
23 Correct 5 ms 5072 KB Output is correct
24 Correct 10 ms 5072 KB Output is correct
25 Correct 11 ms 5144 KB Output is correct
26 Correct 19 ms 5148 KB Output is correct
27 Correct 11 ms 5072 KB Output is correct
28 Correct 14 ms 5072 KB Output is correct
29 Correct 9 ms 5088 KB Output is correct
30 Correct 11 ms 5096 KB Output is correct
31 Correct 3 ms 5072 KB Output is correct
32 Correct 13 ms 5152 KB Output is correct
33 Correct 8 ms 5072 KB Output is correct
34 Correct 8 ms 5072 KB Output is correct
35 Correct 10 ms 5096 KB Output is correct
36 Correct 15 ms 5200 KB Output is correct
37 Correct 17 ms 5216 KB Output is correct
38 Correct 17 ms 5216 KB Output is correct
39 Correct 5 ms 5072 KB Output is correct
40 Correct 7 ms 5116 KB Output is correct
41 Correct 10 ms 5116 KB Output is correct
42 Correct 6 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3037 ms 8076 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3037 ms 8076 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 4 ms 5072 KB Output is correct
4 Correct 4 ms 5072 KB Output is correct
5 Correct 5 ms 5072 KB Output is correct
6 Correct 10 ms 5084 KB Output is correct
7 Correct 11 ms 5072 KB Output is correct
8 Correct 11 ms 5152 KB Output is correct
9 Correct 16 ms 5144 KB Output is correct
10 Correct 14 ms 5200 KB Output is correct
11 Correct 16 ms 5204 KB Output is correct
12 Correct 6 ms 5072 KB Output is correct
13 Execution timed out 3037 ms 8076 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 10 ms 5100 KB Output is correct
4 Correct 10 ms 5072 KB Output is correct
5 Correct 9 ms 5108 KB Output is correct
6 Correct 9 ms 5072 KB Output is correct
7 Correct 10 ms 5104 KB Output is correct
8 Correct 10 ms 5104 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 4 ms 5072 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 5 ms 5072 KB Output is correct
14 Correct 10 ms 5084 KB Output is correct
15 Correct 11 ms 5072 KB Output is correct
16 Correct 11 ms 5152 KB Output is correct
17 Correct 16 ms 5144 KB Output is correct
18 Correct 14 ms 5200 KB Output is correct
19 Correct 16 ms 5204 KB Output is correct
20 Correct 6 ms 5072 KB Output is correct
21 Correct 9 ms 5136 KB Output is correct
22 Correct 5 ms 5072 KB Output is correct
23 Correct 5 ms 5072 KB Output is correct
24 Correct 10 ms 5072 KB Output is correct
25 Correct 11 ms 5144 KB Output is correct
26 Correct 19 ms 5148 KB Output is correct
27 Correct 11 ms 5072 KB Output is correct
28 Correct 14 ms 5072 KB Output is correct
29 Correct 9 ms 5088 KB Output is correct
30 Correct 11 ms 5096 KB Output is correct
31 Correct 3 ms 5072 KB Output is correct
32 Correct 13 ms 5152 KB Output is correct
33 Correct 8 ms 5072 KB Output is correct
34 Correct 8 ms 5072 KB Output is correct
35 Correct 10 ms 5096 KB Output is correct
36 Correct 15 ms 5200 KB Output is correct
37 Correct 17 ms 5216 KB Output is correct
38 Correct 17 ms 5216 KB Output is correct
39 Correct 5 ms 5072 KB Output is correct
40 Correct 7 ms 5116 KB Output is correct
41 Correct 10 ms 5116 KB Output is correct
42 Correct 6 ms 5072 KB Output is correct
43 Correct 1562 ms 5292 KB Output is correct
44 Correct 2195 ms 5348 KB Output is correct
45 Correct 2219 ms 5328 KB Output is correct
46 Execution timed out 3002 ms 5504 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 10 ms 5100 KB Output is correct
4 Correct 10 ms 5072 KB Output is correct
5 Correct 9 ms 5108 KB Output is correct
6 Correct 9 ms 5072 KB Output is correct
7 Correct 10 ms 5104 KB Output is correct
8 Correct 10 ms 5104 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 4 ms 5072 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 5 ms 5072 KB Output is correct
14 Correct 10 ms 5084 KB Output is correct
15 Correct 11 ms 5072 KB Output is correct
16 Correct 11 ms 5152 KB Output is correct
17 Correct 16 ms 5144 KB Output is correct
18 Correct 14 ms 5200 KB Output is correct
19 Correct 16 ms 5204 KB Output is correct
20 Correct 6 ms 5072 KB Output is correct
21 Correct 9 ms 5136 KB Output is correct
22 Correct 5 ms 5072 KB Output is correct
23 Correct 5 ms 5072 KB Output is correct
24 Correct 10 ms 5072 KB Output is correct
25 Correct 11 ms 5144 KB Output is correct
26 Correct 19 ms 5148 KB Output is correct
27 Correct 11 ms 5072 KB Output is correct
28 Correct 14 ms 5072 KB Output is correct
29 Correct 9 ms 5088 KB Output is correct
30 Correct 11 ms 5096 KB Output is correct
31 Correct 3 ms 5072 KB Output is correct
32 Correct 13 ms 5152 KB Output is correct
33 Correct 8 ms 5072 KB Output is correct
34 Correct 8 ms 5072 KB Output is correct
35 Correct 10 ms 5096 KB Output is correct
36 Correct 15 ms 5200 KB Output is correct
37 Correct 17 ms 5216 KB Output is correct
38 Correct 17 ms 5216 KB Output is correct
39 Correct 5 ms 5072 KB Output is correct
40 Correct 7 ms 5116 KB Output is correct
41 Correct 10 ms 5116 KB Output is correct
42 Correct 6 ms 5072 KB Output is correct
43 Execution timed out 3037 ms 8076 KB Time limit exceeded
44 Halted 0 ms 0 KB -