답안 #1071754

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

const long long modulo = 1e9+2022;

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

void init(int N,int M,vector<int> P,vector<int> A){
    ::N = N;
    ::M = M;
    ::A = A;
    arr = vector<long long>(M);
    vector<vector<int>> adj(N);
    vector<vector<pair<long long,long long>>> ways(N);
    for(int i=1;i<N+M;i++){adj[P[i]].emplace_back(i);ways[P[i]].emplace_back(1,1);}
    {
        function<long long(int)> dfs = [&](int x){
            if(x>=N)return 1ll;
            long long tot_ways = adj[x].size();
            for(int i=0;i<adj[x].size();i++) {
                ways[x][i].first=ways[x][i].second=dfs(adj[x][i]);
                tot_ways=(tot_ways*ways[x][i].first)%modulo;
                if(i)ways[x][i].first=(ways[x][i].first*ways[x][i-1].first)%modulo;
            }
            for(int i=adj[x].size()-2;i>=0;i--)ways[x][i].second=(ways[x][i].second*ways[x][i+1].second)%modulo;
            return tot_ways;
        };
        dfs(0);
    }
    {
        function<void(int,long long)> dfs = [&](int x,long long offset) {
            if(x>=N) {
                arr[x-N]=offset;
                return;
            }
            for(int i=0;i<adj[x].size();i++) {
                long long tot = offset;
                if(i)tot=(tot*ways[x][i-1].first)%modulo;
                if(i!=adj[x].size()-1)tot=(tot*ways[x][i+1].second)%modulo;
                dfs(adj[x][i],tot);
            }
        };
        dfs(0,1);
    }
}

int count_ways(int L,int R){
    L-=N;R-=N;
    for(int i=L;i<=R;i++)A[i]^=1;
    long long ans = 0;
    for(int i=0;i<M;i++) {
        if(A[i])ans+=arr[i];
        ans%=modulo;
    }
    return ans;
}

Compilation message

circuit.cpp: In lambda function:
circuit.cpp:25:26: 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[x].size();i++) {
      |                         ~^~~~~~~~~~~~~~
circuit.cpp: In lambda function:
circuit.cpp:41:26: 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<adj[x].size();i++) {
      |                         ~^~~~~~~~~~~~~~
circuit.cpp:44:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |                 if(i!=adj[x].size()-1)tot=(tot*ways[x][i+1].second)%modulo;
      |                    ~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 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 1 ms 420 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 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 344 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 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 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 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 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 420 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 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 344 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 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 600 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 600 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 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 0 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3025 ms 5548 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3025 ms 5548 KB Time limit exceeded
2 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 1 ms 420 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 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 344 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Execution timed out 3025 ms 5548 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 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 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 420 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 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 344 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 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 600 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 600 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 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 0 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 1215 ms 856 KB Output is correct
44 Correct 1595 ms 1108 KB Output is correct
45 Correct 1707 ms 856 KB Output is correct
46 Correct 2403 ms 1364 KB Output is correct
47 Correct 2461 ms 1112 KB Output is correct
48 Correct 2508 ms 1112 KB Output is correct
49 Correct 2480 ms 1112 KB Output is correct
50 Correct 2591 ms 1112 KB Output is correct
51 Correct 2580 ms 600 KB Output is correct
52 Correct 2475 ms 600 KB Output is correct
53 Correct 580 ms 1368 KB Output is correct
54 Correct 2469 ms 1112 KB Output is correct
55 Correct 2450 ms 856 KB Output is correct
56 Correct 2462 ms 868 KB Output is correct
57 Correct 2415 ms 600 KB Output is correct
58 Correct 2459 ms 1624 KB Output is correct
59 Correct 2475 ms 1624 KB Output is correct
60 Correct 2612 ms 1624 KB Output is correct
61 Correct 1487 ms 856 KB Output is correct
62 Correct 1962 ms 600 KB Output is correct
63 Correct 2041 ms 600 KB Output is correct
64 Correct 2463 ms 600 KB Output is correct
65 Correct 720 ms 600 KB Output is correct
66 Correct 2165 ms 856 KB Output is correct
67 Correct 2175 ms 856 KB Output is correct
68 Correct 2248 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 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 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 420 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 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 344 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 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 600 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 600 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 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 0 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Execution timed out 3025 ms 5548 KB Time limit exceeded
44 Halted 0 ms 0 KB -