답안 #1070149

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1070149 2024-08-22T11:54:50 Z Unforgettablepl 디지털 회로 (IOI22_circuit) C++17
18 / 100
3000 ms 2904 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

const long long modulo = 1e9+2022;

namespace {
    int N,M;
    vector<vector<int>> adj;
    vector<int> A;
}

void init(int N,int M,vector<int> P,vector<int> A){
    ::N = N;
    ::M = M;
    ::A = move(A);
    adj = vector<vector<int>>(N);
    for(int i=1;i<N+M;i++)adj[P[i]].emplace_back(i);
}

int count_ways(int L,int R){
    for(int i=L;i<=R;i++)A[i-N]^=1;
    function<pair<long long,long long>(int)> dfs = [&](int x)->pair<long long,long long>{
        if(x>=N) {
            return {A[x-N],1};
        }
        long long tot_ways = adj[x].size();
        vector<long long> DP(adj[x].size()+1);
        DP[0]=1;
        for(int&i:adj[x]) {
            auto temp = dfs(i);
            tot_ways*=temp.second;
            tot_ways%=modulo;
            long long bad_ways = (temp.second-temp.first+modulo)%modulo;
            for(int j=adj[x].size();j>=0;j--) {
                DP[j]*=bad_ways;
                DP[j]%=modulo;
                if(j)DP[j]+=temp.first*DP[j-1];
                DP[j]%=modulo;
            }
        }
        long long ans = 0;
        for(long long i=1;i<=adj[x].size();i++) {
            ans+=DP[i]*i;
            ans%=modulo;
        }
        return {ans,tot_ways};
    };
    return dfs(0).first;
}

Compilation message

circuit.cpp: In lambda function:
circuit.cpp:43:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for(long long i=1;i<=adj[x].size();i++) {
      |                           ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 16 ms 460 KB Output is correct
4 Correct 20 ms 344 KB Output is correct
5 Correct 17 ms 344 KB Output is correct
6 Correct 17 ms 344 KB Output is correct
7 Correct 18 ms 344 KB Output is correct
8 Correct 20 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 436 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 16 ms 460 KB Output is correct
4 Correct 20 ms 344 KB Output is correct
5 Correct 17 ms 344 KB Output is correct
6 Correct 17 ms 344 KB Output is correct
7 Correct 18 ms 344 KB Output is correct
8 Correct 20 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 436 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 17 ms 344 KB Output is correct
30 Correct 18 ms 344 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 2 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 2 ms 432 KB Output is correct
35 Correct 4 ms 344 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 17 ms 600 KB Output is correct
38 Correct 17 ms 600 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3010 ms 2904 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3010 ms 2904 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 436 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Execution timed out 3010 ms 2904 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 16 ms 460 KB Output is correct
4 Correct 20 ms 344 KB Output is correct
5 Correct 17 ms 344 KB Output is correct
6 Correct 17 ms 344 KB Output is correct
7 Correct 18 ms 344 KB Output is correct
8 Correct 20 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 436 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 17 ms 344 KB Output is correct
30 Correct 18 ms 344 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 2 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 2 ms 432 KB Output is correct
35 Correct 4 ms 344 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 17 ms 600 KB Output is correct
38 Correct 17 ms 600 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Execution timed out 3043 ms 600 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 16 ms 460 KB Output is correct
4 Correct 20 ms 344 KB Output is correct
5 Correct 17 ms 344 KB Output is correct
6 Correct 17 ms 344 KB Output is correct
7 Correct 18 ms 344 KB Output is correct
8 Correct 20 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 436 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 17 ms 344 KB Output is correct
30 Correct 18 ms 344 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 2 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 2 ms 432 KB Output is correct
35 Correct 4 ms 344 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 17 ms 600 KB Output is correct
38 Correct 17 ms 600 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Execution timed out 3010 ms 2904 KB Time limit exceeded
44 Halted 0 ms 0 KB -