Submission #634884

# Submission time Handle Problem Language Result Execution time Memory
634884 2022-08-25T08:08:54 Z keta_tsimakuridze Digital Circuit (IOI22_circuit) C++17
2 / 100
3000 ms 7452 KB
#include "circuit.h"
#include <bits/stdc++.h>2
#define ll long long
using namespace std;
#include <vector>
const int N = 2e5 + 5, mod = 1000002022;
int sub[N], k[N], n, m, a[N];
vector<int> V[N];
void dfs(int u) {
    sub[u] = 1;
    if(V[u].size()) sub[u] = sub[u] * V[u].size() % mod;
    for(int i = 0; i < V[u].size(); i++) {
        dfs(V[u][i]);
        sub[u] = sub[u] * sub[V[u][i]] % mod;
    }
}
void dfs2(int u, int cur) {
    vector<int> p(V[u].size()), s(V[u].size());
    k[u] = cur;
    for(int i = 0; i < V[u].size(); i++) {
        p[i] = sub[V[u][i]];
        if(i) p[i] = (ll)p[i] * p[i - 1] % mod;
    }
    for(int i = (int)V[u].size() - 1; i >= 0; i--) {
        s[i] = sub[V[u][i]];
        if(i + 1 != V[u].size()) s[i] = (ll)s[i + 1] * s[i] % mod;
    }
    for(int i = 0; i < V[u].size(); i++) {
        int x = 1;
        if(i) x = (ll)x * p[i - 1] % mod;
        if(i + 1 != V[u].size()) x = (ll)x * s[i + 1] % mod;

        dfs2(V[u][i], (ll)cur * x % mod);
    }
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
    n = N, m = M;
    for(int i = 1; i < N + M; i++) {
        V[P[i]].push_back(i);
    }

    for(int i = N; i < N + M; i++) a[i] = A[i - N];

    dfs(0);
    dfs2(0, 1);
}

int count_ways(int L, int R) {


  for(int i = L; i <= R; i++) {
    a[i] ^= 1;
  }
  int ans = 0;
  for(int i = n; i < n + m; i++) {
    ans = (ans + (ll)a[i] * k[i] % mod) % mod;
  }
  return ans;
}

Compilation message

circuit.cpp:2:25: warning: extra tokens at end of #include directive
    2 | #include <bits/stdc++.h>2
      |                         ^
circuit.cpp: In function 'void dfs(int)':
circuit.cpp:12:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i = 0; i < V[u].size(); i++) {
      |                    ~~^~~~~~~~~~~~~
circuit.cpp: In function 'void dfs2(int, int)':
circuit.cpp:20:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i = 0; i < V[u].size(); i++) {
      |                    ~~^~~~~~~~~~~~~
circuit.cpp:26:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         if(i + 1 != V[u].size()) s[i] = (ll)s[i + 1] * s[i] % mod;
      |            ~~~~~~^~~~~~~~~~~~~~
circuit.cpp:28:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i = 0; i < V[u].size(); i++) {
      |                    ~~^~~~~~~~~~~~~
circuit.cpp:31:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         if(i + 1 != V[u].size()) x = (ll)x * s[i + 1] % mod;
      |            ~~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 5020 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 3 ms 4944 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Incorrect 2 ms 5000 KB 1st lines differ - on the 1st token, expected: '52130940', found: '971487268'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 5020 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 3 ms 4944 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Incorrect 2 ms 5000 KB 1st lines differ - on the 1st token, expected: '52130940', found: '971487268'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3081 ms 7452 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3081 ms 7452 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Incorrect 2 ms 5000 KB 1st lines differ - on the 1st token, expected: '52130940', found: '971487268'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 5020 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 3 ms 4944 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Incorrect 2 ms 5000 KB 1st lines differ - on the 1st token, expected: '52130940', found: '971487268'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 5020 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 3 ms 4944 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Incorrect 2 ms 5000 KB 1st lines differ - on the 1st token, expected: '52130940', found: '971487268'
11 Halted 0 ms 0 KB -