Submission #757152

# Submission time Handle Problem Language Result Execution time Memory
757152 2023-06-12T17:46:57 Z boris_mihov Digital Circuit (IOI22_circuit) C++17
2 / 100
3000 ms 8076 KB
#include "circuit.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
 
typedef long long llong;
const int MAXN = 200000 + 10;
const int MOD = 1000002022;
const int INF = 1e9;
 
int n, m;
llong w[MAXN];
llong b[MAXN];
llong pw[MAXN];
llong multBy[MAXN];
std::vector <int> g[MAXN];

void initDFS(int node)
{
    if (g[node].empty())
    {
        pw[node] = 1;
        return;
    }
    
    pw[node] = g[node].size();
    for (const int &i : g[node])
    {
        initDFS(i);
        pw[node] *= pw[i];
        pw[node] %= MOD;
    }
}

void findMult(int node, llong mult)
{
    if (g[node].empty())
    {
        multBy[node] = mult;
        return;
    }
    
    for (const int &i : g[node])
    {
        findMult(i, mult * ((pw[node] / pw[i]) / g[node].size()));
    }
}

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)
    {
        g[P[i] + 1].push_back(i + 1);
    }
 
    for (int i = n + 1 ; i <= n + m ; ++i)
    {
        if (A[i - n - 1] == 0)
        {
            w[i] = 1;
            b[i] = 0;
        } else
        {
            b[i] = 1;
            w[i] = 0;
        }
    }

    initDFS(1);
    findMult(1, 1);
}
 
int count_ways(int L, int R) 
{
    L++; R++;
    for (int i = L ; i <= R ; ++i)
    {
        std::swap(b[i], w[i]);
    }
 
    llong res = 0;
    for (int i = n + 1 ; i <= n + m ; ++i)
    {
        res += multBy[i] * b[i];
        if (res >= MOD) res -= MOD;
    }

    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3036 ms 8076 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3036 ms 8076 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
11 Halted 0 ms 0 KB -