답안 #836193

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
836193 2023-08-24T08:34:05 Z SamAnd 디지털 회로 (IOI22_circuit) C++17
2 / 100
1610 ms 7248 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
const int N = 200005, M = 1000002022;

int n, m;
vector<int> g[N];
int s[N];

int a[N];
void dfs0(int x)
{
    a[x] = 1;
    if (g[x].empty())
        return;
    for (int i = 0; i < g[x].size(); ++i)
    {
        int h = g[x][i];
        dfs0(h);
        a[x] = (a[x] * 1LL * a[h]) % M;
    }
    a[x] = (a[x] * 1LL * sz(g[x])) % M;
}

int u[N];
void dfs1(int x, int aa)
{
    if (g[x].empty())
    {
        u[x - n] = aa;
        return;
    }

    vector<int> p;
    for (int i = 0; i < g[x].size(); ++i)
    {
        int h = g[x][i];
        if (p.empty())
            p.push_back(a[h]);
        else
            p.push_back((p.back() * 1LL * a[h]) % M);
    }
    vector<int> s;
    for (int i = sz(g[x]) - 1; i >= 0; --i)
    {
        int h = g[x][i];
        if (s.empty())
            s.push_back(a[h]);
        else
            s.push_back((s.back() * 1LL * a[h]) % M);
    }
    reverse(all(s));

    for (int i = 0; i < g[x].size(); ++i)
    {
        int h = g[x][i];
        int yaa = aa;
        if (i)
            yaa = (yaa * 1LL * p[i - 1]) % M;
        if (i + 1 < sz(g[x]))
            yaa = (yaa * 1LL * s[i + 1]) % M;
        dfs1(h, yaa);
    }
}

void init(int NN, int MM, std::vector<int> P, std::vector<int> A)
{
    n = NN;
    m = MM;
    for (int i = 1; i < n + m; ++i)
        g[P[i]].push_back(i);
    for (int i = 0; i < m; ++i)
        s[i] = A[i];
    dfs0(0);
    dfs1(0, 1);
}

int count_ways(int L, int R)
{
    L -= n;
    R -= n;
    for (int i = L; i <= R; ++i)
        s[i] ^= 1;
    int ans = 0;
    for (int i = 0; i < m; ++i)
    {
        ans += s[i] * u[i];
    }
    return ans;
}

/*
3 4 3
-1 0 1 2 1 1 0
1 0 1 0
3 4
4 5
3 6
*/

Compilation message

circuit.cpp: In function 'void dfs0(int)':
circuit.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for (int i = 0; i < g[x].size(); ++i)
      |                     ~~^~~~~~~~~~~~~
circuit.cpp: In function 'void dfs1(int, int)':
circuit.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for (int i = 0; i < g[x].size(); ++i)
      |                     ~~^~~~~~~~~~~~~
circuit.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for (int i = 0; i < g[x].size(); ++i)
      |                     ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 4944 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Correct 2 ms 4940 KB Output is correct
6 Correct 2 ms 4980 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 2 ms 4944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Incorrect 2 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 4944 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Correct 2 ms 4940 KB Output is correct
6 Correct 2 ms 4980 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 2 ms 4944 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Incorrect 2 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1610 ms 7248 KB 1st lines differ - on the 1st token, expected: '431985922', found: '-747097920'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1610 ms 7248 KB 1st lines differ - on the 1st token, expected: '431985922', found: '-747097920'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Incorrect 2 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 4944 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Correct 2 ms 4940 KB Output is correct
6 Correct 2 ms 4980 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 2 ms 4944 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Incorrect 2 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 4944 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Correct 2 ms 4940 KB Output is correct
6 Correct 2 ms 4980 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 2 ms 4944 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Incorrect 2 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -