Submission #582551

# Submission time Handle Problem Language Result Execution time Memory
582551 2022-06-24T05:23:54 Z 박상훈(#8369) Amusement Park (CEOI19_amusementpark) C++17
63 / 100
3000 ms 2448 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
const int MOD = 998244353;
int adj[20][20], dp1[(1<<18)], dp2[(1<<18)], p[(1<<18)], cnt[18];

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i=1;i<=m;i++){
        int x, y;
        scanf("%d %d", &x, &y);
        --x, --y;
        adj[x][y] = 1;
        adj[y][x] = -1;
    }

    for (int z=0;z<(1<<n);z++){
        p[z] = 1;
        for (int i=0;i<n;i++) if (z&(1<<i)){
            for (int j=i+1;j<n;j++) if (z&(1<<j)){
                if (adj[i][j]) p[z] = 0;
            }
        }
    }

    for (int z=0;z<(1<<n);z++) if (__builtin_popcount(z)<2) dp2[z] = 1;

    for (int z=0;z<(1<<n);z++) if (__builtin_popcount(z)>=2){
        memset(cnt, 0, sizeof(cnt));
        for (int i=0;i<n;i++) if (z&(1<<i)){
            for (int j=0;j<n;j++) if (z&(1<<j) && adj[i][j]==-1) cnt[i]++;
        }


        for (int z2=z;z2;z2=(z2-1)&z) if (p[z2]){
            ll cst = 0;
            for (int i=0;i<n;i++) if (z2&(1<<i)) cst += cnt[i];

            if (__builtin_popcount(z2)&1){
                dp1[z] += (cst * dp2[z^z2] + dp1[z^z2]) % MOD;
                dp2[z] += dp2[z^z2];

                if (dp1[z]>=MOD) dp1[z] -= MOD;
                if (dp2[z]>=MOD) dp2[z] -= MOD;
            }
            else{
                dp1[z] -= (cst * dp2[z^z2] + dp1[z^z2]) % MOD;
                dp2[z] -= dp2[z^z2];

                if (dp1[z]<0) dp1[z] += MOD;
                if (dp2[z]<0) dp2[z] += MOD;
            }
        }
    }
    printf("%d\n", dp1[(1<<n)-1]);
    return 0;
}

Compilation message

amusementpark.cpp: In function 'int main()':
amusementpark.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
amusementpark.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 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 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 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 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 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 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 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 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 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 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 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 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 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 312 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
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 3 ms 340 KB Output is correct
53 Correct 3 ms 212 KB Output is correct
54 Correct 2 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 2 ms 388 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 2 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 3 ms 212 KB Output is correct
62 Correct 2 ms 212 KB Output is correct
63 Correct 2 ms 212 KB Output is correct
64 Correct 2 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 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 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 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 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 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 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 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 312 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
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 3 ms 340 KB Output is correct
53 Correct 3 ms 212 KB Output is correct
54 Correct 2 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 2 ms 388 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 2 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 3 ms 212 KB Output is correct
62 Correct 2 ms 212 KB Output is correct
63 Correct 2 ms 212 KB Output is correct
64 Correct 2 ms 212 KB Output is correct
65 Correct 37 ms 468 KB Output is correct
66 Correct 34 ms 424 KB Output is correct
67 Correct 31 ms 468 KB Output is correct
68 Correct 29 ms 468 KB Output is correct
69 Correct 193 ms 468 KB Output is correct
70 Correct 127 ms 432 KB Output is correct
71 Correct 121 ms 420 KB Output is correct
72 Correct 116 ms 496 KB Output is correct
73 Correct 95 ms 468 KB Output is correct
74 Correct 82 ms 484 KB Output is correct
75 Correct 80 ms 464 KB Output is correct
76 Correct 82 ms 436 KB Output is correct
77 Correct 171 ms 688 KB Output is correct
78 Correct 114 ms 608 KB Output is correct
79 Correct 90 ms 676 KB Output is correct
80 Correct 81 ms 692 KB Output is correct
81 Correct 80 ms 668 KB Output is correct
82 Correct 71 ms 636 KB Output is correct
83 Correct 64 ms 644 KB Output is correct
84 Correct 58 ms 592 KB Output is correct
85 Correct 584 ms 800 KB Output is correct
86 Correct 374 ms 664 KB Output is correct
87 Correct 394 ms 628 KB Output is correct
88 Correct 351 ms 732 KB Output is correct
89 Correct 270 ms 772 KB Output is correct
90 Correct 249 ms 716 KB Output is correct
91 Correct 246 ms 680 KB Output is correct
92 Correct 253 ms 728 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 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 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 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 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 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 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 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 312 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
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 3 ms 340 KB Output is correct
53 Correct 3 ms 212 KB Output is correct
54 Correct 2 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 2 ms 388 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 2 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 3 ms 212 KB Output is correct
62 Correct 2 ms 212 KB Output is correct
63 Correct 2 ms 212 KB Output is correct
64 Correct 2 ms 212 KB Output is correct
65 Correct 37 ms 468 KB Output is correct
66 Correct 34 ms 424 KB Output is correct
67 Correct 31 ms 468 KB Output is correct
68 Correct 29 ms 468 KB Output is correct
69 Correct 193 ms 468 KB Output is correct
70 Correct 127 ms 432 KB Output is correct
71 Correct 121 ms 420 KB Output is correct
72 Correct 116 ms 496 KB Output is correct
73 Correct 95 ms 468 KB Output is correct
74 Correct 82 ms 484 KB Output is correct
75 Correct 80 ms 464 KB Output is correct
76 Correct 82 ms 436 KB Output is correct
77 Correct 171 ms 688 KB Output is correct
78 Correct 114 ms 608 KB Output is correct
79 Correct 90 ms 676 KB Output is correct
80 Correct 81 ms 692 KB Output is correct
81 Correct 80 ms 668 KB Output is correct
82 Correct 71 ms 636 KB Output is correct
83 Correct 64 ms 644 KB Output is correct
84 Correct 58 ms 592 KB Output is correct
85 Correct 584 ms 800 KB Output is correct
86 Correct 374 ms 664 KB Output is correct
87 Correct 394 ms 628 KB Output is correct
88 Correct 351 ms 732 KB Output is correct
89 Correct 270 ms 772 KB Output is correct
90 Correct 249 ms 716 KB Output is correct
91 Correct 246 ms 680 KB Output is correct
92 Correct 253 ms 728 KB Output is correct
93 Execution timed out 3070 ms 2448 KB Time limit exceeded
94 Halted 0 ms 0 KB -