Submission #544507

# Submission time Handle Problem Language Result Execution time Memory
544507 2022-04-02T07:03:15 Z model_code Sprinkler (JOI22_sprinkler) C++17
100 / 100
1014 ms 52340 KB
#include <array>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
const int D_MAX = 40;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;
    auto mul = [M](int a, int b) -> int { return int64_t(a) * b % M; };
    vector g(N, vector<int>{});
    for(int i = 0; i < N - 1; i++){
        int A, B;
        cin >> A >> B;
        A--; B--;
        g[A].push_back(B);
        g[B].push_back(A);
    }
    vector<int> parent(N);
    auto dfs = [&](int par, int x, auto dfs) -> void {
        parent[x] = par;
        for(int y : g[x]) if(y != par) dfs(x, y, dfs);
    };
    dfs(-1, 0, dfs);
    vector dp(N, array<int, D_MAX + 1>{});
    for(auto& v : dp) v.fill(1);
    for(int i = 0; i < N; i++) cin >> dp[i][0];
    int Q;
    cin >> Q;
    for(int t = 0; t < Q; t++){
        int type, x;
        cin >> type >> x;
        x--;
        if(type == 1){
            int d, c;
            cin >> d >> c;
            while(1){
                dp[x][d] = mul(dp[x][d], c);
                if(d-- == 0) break;
                dp[x][d] = mul(dp[x][d], c);
                if(x) x = parent[x];
                else if(d-- == 0) break;
            }
        }
        else{
            int ans = 1;
            for(int d = 0; d <= D_MAX && x >= 0; d++, x = parent[x]){
                ans = mul(ans, dp[x][d]);
            }
            cout << ans << '\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 733 ms 47812 KB Output is correct
3 Correct 509 ms 44616 KB Output is correct
4 Correct 580 ms 49184 KB Output is correct
5 Correct 559 ms 46116 KB Output is correct
6 Correct 475 ms 46076 KB Output is correct
7 Correct 417 ms 46472 KB Output is correct
8 Correct 378 ms 46848 KB Output is correct
9 Correct 795 ms 52340 KB Output is correct
10 Correct 528 ms 48816 KB Output is correct
11 Correct 739 ms 47720 KB Output is correct
12 Correct 504 ms 44544 KB Output is correct
13 Correct 260 ms 45120 KB Output is correct
14 Correct 313 ms 45236 KB Output is correct
15 Correct 318 ms 45216 KB Output is correct
16 Correct 294 ms 45164 KB Output is correct
17 Correct 367 ms 45800 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 733 ms 47812 KB Output is correct
3 Correct 509 ms 44616 KB Output is correct
4 Correct 580 ms 49184 KB Output is correct
5 Correct 559 ms 46116 KB Output is correct
6 Correct 475 ms 46076 KB Output is correct
7 Correct 417 ms 46472 KB Output is correct
8 Correct 378 ms 46848 KB Output is correct
9 Correct 795 ms 52340 KB Output is correct
10 Correct 528 ms 48816 KB Output is correct
11 Correct 739 ms 47720 KB Output is correct
12 Correct 504 ms 44544 KB Output is correct
13 Correct 260 ms 45120 KB Output is correct
14 Correct 313 ms 45236 KB Output is correct
15 Correct 318 ms 45216 KB Output is correct
16 Correct 294 ms 45164 KB Output is correct
17 Correct 367 ms 45800 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 597 ms 47720 KB Output is correct
25 Correct 471 ms 44560 KB Output is correct
26 Correct 591 ms 50636 KB Output is correct
27 Correct 480 ms 46088 KB Output is correct
28 Correct 411 ms 46236 KB Output is correct
29 Correct 348 ms 46280 KB Output is correct
30 Correct 298 ms 46864 KB Output is correct
31 Correct 635 ms 51088 KB Output is correct
32 Correct 411 ms 48892 KB Output is correct
33 Correct 602 ms 47780 KB Output is correct
34 Correct 429 ms 44520 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 320 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 751 ms 49632 KB Output is correct
3 Correct 916 ms 47700 KB Output is correct
4 Correct 709 ms 48260 KB Output is correct
5 Correct 643 ms 44592 KB Output is correct
6 Correct 516 ms 44660 KB Output is correct
7 Correct 470 ms 44868 KB Output is correct
8 Correct 350 ms 45264 KB Output is correct
9 Correct 750 ms 48304 KB Output is correct
10 Correct 1014 ms 48420 KB Output is correct
11 Correct 673 ms 44912 KB Output is correct
12 Correct 862 ms 44388 KB Output is correct
13 Correct 603 ms 45204 KB Output is correct
14 Correct 595 ms 45744 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 721 ms 50832 KB Output is correct
3 Correct 968 ms 46960 KB Output is correct
4 Correct 719 ms 48884 KB Output is correct
5 Correct 635 ms 46156 KB Output is correct
6 Correct 447 ms 46332 KB Output is correct
7 Correct 438 ms 46284 KB Output is correct
8 Correct 297 ms 46668 KB Output is correct
9 Correct 698 ms 51932 KB Output is correct
10 Correct 915 ms 48948 KB Output is correct
11 Correct 656 ms 47720 KB Output is correct
12 Correct 787 ms 44596 KB Output is correct
13 Correct 593 ms 45316 KB Output is correct
14 Correct 584 ms 45800 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 733 ms 47812 KB Output is correct
31 Correct 509 ms 44616 KB Output is correct
32 Correct 580 ms 49184 KB Output is correct
33 Correct 559 ms 46116 KB Output is correct
34 Correct 475 ms 46076 KB Output is correct
35 Correct 417 ms 46472 KB Output is correct
36 Correct 378 ms 46848 KB Output is correct
37 Correct 795 ms 52340 KB Output is correct
38 Correct 528 ms 48816 KB Output is correct
39 Correct 739 ms 47720 KB Output is correct
40 Correct 504 ms 44544 KB Output is correct
41 Correct 260 ms 45120 KB Output is correct
42 Correct 313 ms 45236 KB Output is correct
43 Correct 318 ms 45216 KB Output is correct
44 Correct 294 ms 45164 KB Output is correct
45 Correct 367 ms 45800 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 597 ms 47720 KB Output is correct
53 Correct 471 ms 44560 KB Output is correct
54 Correct 591 ms 50636 KB Output is correct
55 Correct 480 ms 46088 KB Output is correct
56 Correct 411 ms 46236 KB Output is correct
57 Correct 348 ms 46280 KB Output is correct
58 Correct 298 ms 46864 KB Output is correct
59 Correct 635 ms 51088 KB Output is correct
60 Correct 411 ms 48892 KB Output is correct
61 Correct 602 ms 47780 KB Output is correct
62 Correct 429 ms 44520 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 1 ms 320 KB Output is correct
68 Correct 1 ms 212 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 1 ms 212 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 751 ms 49632 KB Output is correct
80 Correct 916 ms 47700 KB Output is correct
81 Correct 709 ms 48260 KB Output is correct
82 Correct 643 ms 44592 KB Output is correct
83 Correct 516 ms 44660 KB Output is correct
84 Correct 470 ms 44868 KB Output is correct
85 Correct 350 ms 45264 KB Output is correct
86 Correct 750 ms 48304 KB Output is correct
87 Correct 1014 ms 48420 KB Output is correct
88 Correct 673 ms 44912 KB Output is correct
89 Correct 862 ms 44388 KB Output is correct
90 Correct 603 ms 45204 KB Output is correct
91 Correct 595 ms 45744 KB Output is correct
92 Correct 1 ms 212 KB Output is correct
93 Correct 1 ms 212 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 0 ms 212 KB Output is correct
98 Correct 721 ms 50832 KB Output is correct
99 Correct 968 ms 46960 KB Output is correct
100 Correct 719 ms 48884 KB Output is correct
101 Correct 635 ms 46156 KB Output is correct
102 Correct 447 ms 46332 KB Output is correct
103 Correct 438 ms 46284 KB Output is correct
104 Correct 297 ms 46668 KB Output is correct
105 Correct 698 ms 51932 KB Output is correct
106 Correct 915 ms 48948 KB Output is correct
107 Correct 656 ms 47720 KB Output is correct
108 Correct 787 ms 44596 KB Output is correct
109 Correct 593 ms 45316 KB Output is correct
110 Correct 584 ms 45800 KB Output is correct
111 Correct 1 ms 212 KB Output is correct
112 Correct 1 ms 212 KB Output is correct
113 Correct 1 ms 212 KB Output is correct
114 Correct 1 ms 212 KB Output is correct
115 Correct 1 ms 212 KB Output is correct
116 Correct 660 ms 45672 KB Output is correct
117 Correct 836 ms 44464 KB Output is correct
118 Correct 745 ms 50508 KB Output is correct
119 Correct 652 ms 46104 KB Output is correct
120 Correct 431 ms 46116 KB Output is correct
121 Correct 448 ms 46420 KB Output is correct
122 Correct 360 ms 46924 KB Output is correct
123 Correct 726 ms 51460 KB Output is correct
124 Correct 961 ms 47388 KB Output is correct
125 Correct 622 ms 47100 KB Output is correct
126 Correct 855 ms 44408 KB Output is correct
127 Correct 878 ms 44364 KB Output is correct
128 Correct 613 ms 45316 KB Output is correct
129 Correct 644 ms 45740 KB Output is correct