Submission #615096

# Submission time Handle Problem Language Result Execution time Memory
615096 2022-07-31T06:45:47 Z 조영욱(#8494) Sprinkler (JOI22_sprinkler) C++17
38 / 100
505 ms 41764 KB
#include <bits/stdc++.h>
using namespace std;

int n,mod;
vector<int> adj[200001];
int par[200001];
long long h[200001];
long long save[200001][3][3];

void dfs(int v,int prev) {
    par[v]=prev;
    for(int i=0;i<adj[v].size();i++) {
        int nt=adj[v][i];
        if (nt!=prev) {
            dfs(nt,v);
        }
    }
}

int main(void) {
    scanf("%d %d",&n,&mod);
    for(int i=1;i<n;i++) {
        int u,v;
        scanf("%d %d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=1;i<=n;i++) {
        scanf("%lld",&h[i]);
    }
    dfs(1,-1);
    for(int i=1;i<=n;i++) {
        for(int j=0;j<=2;j++) {
            for(int k=0;k<=2;k++)
            save[i][j][k]=1;
        }
    }
    int q;
    scanf("%d",&q);
    for(int i=0;i<q;i++) {
        int type;
        scanf("%d",&type);
        if (type==1) {
            int x,d,w;
            scanf("%d %d %d",&x,&d,&w);
            int now=x;
            for(int i=0;i<=d;i++) {
                if (now==-1) {
                    break;
                }
                save[now][d][i]*=w;
                save[now][d][i]%=mod;
                now=par[now];
            }
        }
        else {
            int x;
            scanf("%d",&x);
            long long ret=h[x];
            for(int d=0;d<=2;d++) {
                int en=d;
                int now=x;
                while (1) {
                    if (en<0) {
                        break;
                    }
                    if (en==0) {
                        ret*=save[now][d][0];
                        ret%=mod;
                        break;
                    }
                    if (par[now]==-1) {
                        for(int j=0;j<=en;j++) {
                            ret*=save[now][d][j];
                            ret%=mod;
                        }
                        break;
                    }
                    ret*=save[now][d][en];
                    ret%=mod;
                    ret*=save[now][d][en-1];
                    ret%=mod;
                    now=par[now];
                    en--;
                }
            }
            printf("%lld\n",ret);
        }
    }
}

Compilation message

sprinkler.cpp: In function 'void dfs(int, int)':
sprinkler.cpp:12:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i=0;i<adj[v].size();i++) {
      |                 ~^~~~~~~~~~~~~~
sprinkler.cpp: In function 'int main()':
sprinkler.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     scanf("%d %d",&n,&mod);
      |     ~~~~~^~~~~~~~~~~~~~~~~
sprinkler.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         scanf("%d %d",&u,&v);
      |         ~~~~~^~~~~~~~~~~~~~~
sprinkler.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf("%lld",&h[i]);
      |         ~~~~~^~~~~~~~~~~~~~
sprinkler.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
sprinkler.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         scanf("%d",&type);
      |         ~~~~~^~~~~~~~~~~~
sprinkler.cpp:45:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |             scanf("%d %d %d",&x,&d,&w);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~
sprinkler.cpp:58:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |             scanf("%d",&x);
      |             ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5020 KB Output is correct
2 Correct 385 ms 31364 KB Output is correct
3 Correct 419 ms 28580 KB Output is correct
4 Correct 450 ms 37172 KB Output is correct
5 Correct 354 ms 31204 KB Output is correct
6 Correct 402 ms 31292 KB Output is correct
7 Correct 407 ms 31524 KB Output is correct
8 Correct 297 ms 31964 KB Output is correct
9 Correct 391 ms 41764 KB Output is correct
10 Correct 394 ms 37956 KB Output is correct
11 Correct 338 ms 32824 KB Output is correct
12 Correct 441 ms 29604 KB Output is correct
13 Correct 287 ms 29632 KB Output is correct
14 Correct 463 ms 29620 KB Output is correct
15 Correct 322 ms 29648 KB Output is correct
16 Correct 336 ms 29644 KB Output is correct
17 Correct 283 ms 30156 KB Output is correct
18 Correct 4 ms 4968 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 5 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5020 KB Output is correct
2 Correct 385 ms 31364 KB Output is correct
3 Correct 419 ms 28580 KB Output is correct
4 Correct 450 ms 37172 KB Output is correct
5 Correct 354 ms 31204 KB Output is correct
6 Correct 402 ms 31292 KB Output is correct
7 Correct 407 ms 31524 KB Output is correct
8 Correct 297 ms 31964 KB Output is correct
9 Correct 391 ms 41764 KB Output is correct
10 Correct 394 ms 37956 KB Output is correct
11 Correct 338 ms 32824 KB Output is correct
12 Correct 441 ms 29604 KB Output is correct
13 Correct 287 ms 29632 KB Output is correct
14 Correct 463 ms 29620 KB Output is correct
15 Correct 322 ms 29648 KB Output is correct
16 Correct 336 ms 29644 KB Output is correct
17 Correct 283 ms 30156 KB Output is correct
18 Correct 4 ms 4968 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 5 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 5008 KB Output is correct
24 Correct 388 ms 32488 KB Output is correct
25 Correct 465 ms 29148 KB Output is correct
26 Correct 505 ms 39296 KB Output is correct
27 Correct 503 ms 30672 KB Output is correct
28 Correct 358 ms 30796 KB Output is correct
29 Correct 381 ms 31480 KB Output is correct
30 Correct 340 ms 31960 KB Output is correct
31 Correct 422 ms 39036 KB Output is correct
32 Correct 496 ms 37900 KB Output is correct
33 Correct 405 ms 32824 KB Output is correct
34 Correct 412 ms 29712 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 4 ms 5024 KB Output is correct
37 Correct 4 ms 4948 KB Output is correct
38 Correct 4 ms 4948 KB Output is correct
39 Correct 4 ms 4948 KB Output is correct
40 Correct 3 ms 4948 KB Output is correct
41 Correct 3 ms 5016 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 4 ms 5016 KB Output is correct
44 Correct 3 ms 4948 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 5 ms 4948 KB Output is correct
48 Correct 3 ms 5012 KB Output is correct
49 Correct 3 ms 5012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 426 ms 38272 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -