Submission #1052464

# Submission time Handle Problem Language Result Execution time Memory
1052464 2024-08-10T14:47:04 Z handlename Amusement Park (CEOI19_amusementpark) C++17
100 / 100
1395 ms 5160 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define float long double
// const int MOD=1e9+7;
const int MOD=998244353;
const int sqn=450;
const long double eps=1e-6;
const int dx[4]={0,0,1,-1};
const int dy[4]={1,-1,0,0};
long long power(long long a,long long b,long long p=MOD){
    long long res=1;
    while (b>0){
        if (b%2==1) res=(res*a)%p;
        b/=2;
        a=(a*a)%p;
    }
    return res;
}
int n,m;
bool adj[20][20],indep[1000001];
// for each legal proposal, reversing the edges creates another
// costs for this pair is m
// sum of costs is m * DAGCount/2
// where DAGCount = number of DAGs on original graph
long long dp[1000001];
// dp[mask] = number of DAGs on graph with mask vertices
// for any DAG, at least 1 vertex has out degree 0
// we loop through all possible subsets of vertices with out degree 0
// this subset must be an independent set
// however, we cannot just add them all up
// as subsets of independent sets are also independent
// to fix double counting, use PIE
void runtc(){
    cin>>n>>m;
    for (int i=1;i<=m;i++){
        int u,v;
        cin>>u>>v;
        u--;
        v--;
        adj[u][v]=adj[v][u]=true;
    }
    memset(indep,true,sizeof(indep));
    for (int i=0;i<(1<<n);i++){
        for (int j=0;j<n;j++){
            for (int k=j+1;k<n;k++){
                if (!(i&(1<<j))) continue;
                if (!(i&(1<<k))) continue;
                if (adj[j][k]) indep[i]=false;
            }
        }
    }
    dp[0]=1;
    for (int i=1;i<(1<<n);i++){
        for (int j=i;j>0;j=(j-1)&i){
            if (!indep[j]) continue;
            if (__builtin_popcount(j)%2==1){
                dp[i]+=dp[i^j];
            }
            else {
                dp[i]-=dp[i^j];
            }
            dp[i]%=MOD;
        }
    }
    long long ans=dp[(1<<n)-1];
    ans*=m;
    ans%=MOD;
    ans*=power(2,MOD-2,MOD);
    ans%=MOD;
    cout<<(ans%MOD+MOD)%MOD;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // freopen("movie.in","r",stdin);
    // freopen("movie.out","w",stdout);
    //freopen("input1.in","r",stdin);
    // freopen("output1.out","w",stdout);
    //freopen("tower_rush_input.txt","r",stdin);
    //freopen("hackercup_output.txt","w",stdout);
    int tcs;
    // cin>>tcs;
    tcs=1;
    for (int i=1;i<=tcs;i++){
        // cout<<"Case #"<<i<<": ";
        runtc();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 0 ms 2908 KB Output is correct
3 Correct 0 ms 2908 KB Output is correct
4 Correct 0 ms 2908 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 0 ms 2908 KB Output is correct
3 Correct 0 ms 2908 KB Output is correct
4 Correct 0 ms 2908 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 0 ms 2908 KB Output is correct
10 Correct 0 ms 2908 KB Output is correct
11 Correct 0 ms 2908 KB Output is correct
12 Correct 0 ms 2908 KB Output is correct
13 Correct 0 ms 2908 KB Output is correct
14 Correct 0 ms 2908 KB Output is correct
15 Correct 0 ms 2908 KB Output is correct
16 Correct 0 ms 2908 KB Output is correct
17 Correct 0 ms 2908 KB Output is correct
18 Correct 0 ms 2908 KB Output is correct
19 Correct 1 ms 2908 KB Output is correct
20 Correct 0 ms 2908 KB Output is correct
21 Correct 0 ms 2908 KB Output is correct
22 Correct 1 ms 2908 KB Output is correct
23 Correct 1 ms 2908 KB Output is correct
24 Correct 0 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 0 ms 2908 KB Output is correct
3 Correct 0 ms 2908 KB Output is correct
4 Correct 0 ms 2908 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 0 ms 2908 KB Output is correct
10 Correct 0 ms 2908 KB Output is correct
11 Correct 0 ms 2908 KB Output is correct
12 Correct 0 ms 2908 KB Output is correct
13 Correct 0 ms 2908 KB Output is correct
14 Correct 0 ms 2908 KB Output is correct
15 Correct 0 ms 2908 KB Output is correct
16 Correct 0 ms 2908 KB Output is correct
17 Correct 0 ms 2908 KB Output is correct
18 Correct 0 ms 2908 KB Output is correct
19 Correct 1 ms 2908 KB Output is correct
20 Correct 0 ms 2908 KB Output is correct
21 Correct 0 ms 2908 KB Output is correct
22 Correct 1 ms 2908 KB Output is correct
23 Correct 1 ms 2908 KB Output is correct
24 Correct 0 ms 2908 KB Output is correct
25 Correct 0 ms 2908 KB Output is correct
26 Correct 0 ms 2908 KB Output is correct
27 Correct 1 ms 2908 KB Output is correct
28 Correct 0 ms 2908 KB Output is correct
29 Correct 1 ms 2904 KB Output is correct
30 Correct 1 ms 2908 KB Output is correct
31 Correct 0 ms 2908 KB Output is correct
32 Correct 1 ms 2908 KB Output is correct
33 Correct 0 ms 2908 KB Output is correct
34 Correct 1 ms 2908 KB Output is correct
35 Correct 1 ms 2908 KB Output is correct
36 Correct 1 ms 2908 KB Output is correct
37 Correct 0 ms 2868 KB Output is correct
38 Correct 0 ms 2908 KB Output is correct
39 Correct 0 ms 2908 KB Output is correct
40 Correct 1 ms 2904 KB Output is correct
41 Correct 1 ms 2908 KB Output is correct
42 Correct 0 ms 2908 KB Output is correct
43 Correct 0 ms 2908 KB Output is correct
44 Correct 1 ms 2908 KB Output is correct
45 Correct 1 ms 2908 KB Output is correct
46 Correct 1 ms 2908 KB Output is correct
47 Correct 1 ms 2908 KB Output is correct
48 Correct 1 ms 2908 KB Output is correct
49 Correct 1 ms 2908 KB Output is correct
50 Correct 1 ms 2908 KB Output is correct
51 Correct 0 ms 2908 KB Output is correct
52 Correct 1 ms 2908 KB Output is correct
53 Correct 1 ms 2904 KB Output is correct
54 Correct 1 ms 2908 KB Output is correct
55 Correct 1 ms 2908 KB Output is correct
56 Correct 1 ms 2908 KB Output is correct
57 Correct 1 ms 2904 KB Output is correct
58 Correct 1 ms 2908 KB Output is correct
59 Correct 1 ms 2908 KB Output is correct
60 Correct 0 ms 2908 KB Output is correct
61 Correct 1 ms 2908 KB Output is correct
62 Correct 1 ms 2908 KB Output is correct
63 Correct 1 ms 2908 KB Output is correct
64 Correct 1 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 0 ms 2908 KB Output is correct
3 Correct 0 ms 2908 KB Output is correct
4 Correct 0 ms 2908 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 0 ms 2908 KB Output is correct
10 Correct 0 ms 2908 KB Output is correct
11 Correct 0 ms 2908 KB Output is correct
12 Correct 0 ms 2908 KB Output is correct
13 Correct 0 ms 2908 KB Output is correct
14 Correct 0 ms 2908 KB Output is correct
15 Correct 0 ms 2908 KB Output is correct
16 Correct 0 ms 2908 KB Output is correct
17 Correct 0 ms 2908 KB Output is correct
18 Correct 0 ms 2908 KB Output is correct
19 Correct 1 ms 2908 KB Output is correct
20 Correct 0 ms 2908 KB Output is correct
21 Correct 0 ms 2908 KB Output is correct
22 Correct 1 ms 2908 KB Output is correct
23 Correct 1 ms 2908 KB Output is correct
24 Correct 0 ms 2908 KB Output is correct
25 Correct 0 ms 2908 KB Output is correct
26 Correct 0 ms 2908 KB Output is correct
27 Correct 1 ms 2908 KB Output is correct
28 Correct 0 ms 2908 KB Output is correct
29 Correct 1 ms 2904 KB Output is correct
30 Correct 1 ms 2908 KB Output is correct
31 Correct 0 ms 2908 KB Output is correct
32 Correct 1 ms 2908 KB Output is correct
33 Correct 0 ms 2908 KB Output is correct
34 Correct 1 ms 2908 KB Output is correct
35 Correct 1 ms 2908 KB Output is correct
36 Correct 1 ms 2908 KB Output is correct
37 Correct 0 ms 2868 KB Output is correct
38 Correct 0 ms 2908 KB Output is correct
39 Correct 0 ms 2908 KB Output is correct
40 Correct 1 ms 2904 KB Output is correct
41 Correct 1 ms 2908 KB Output is correct
42 Correct 0 ms 2908 KB Output is correct
43 Correct 0 ms 2908 KB Output is correct
44 Correct 1 ms 2908 KB Output is correct
45 Correct 1 ms 2908 KB Output is correct
46 Correct 1 ms 2908 KB Output is correct
47 Correct 1 ms 2908 KB Output is correct
48 Correct 1 ms 2908 KB Output is correct
49 Correct 1 ms 2908 KB Output is correct
50 Correct 1 ms 2908 KB Output is correct
51 Correct 0 ms 2908 KB Output is correct
52 Correct 1 ms 2908 KB Output is correct
53 Correct 1 ms 2904 KB Output is correct
54 Correct 1 ms 2908 KB Output is correct
55 Correct 1 ms 2908 KB Output is correct
56 Correct 1 ms 2908 KB Output is correct
57 Correct 1 ms 2904 KB Output is correct
58 Correct 1 ms 2908 KB Output is correct
59 Correct 1 ms 2908 KB Output is correct
60 Correct 0 ms 2908 KB Output is correct
61 Correct 1 ms 2908 KB Output is correct
62 Correct 1 ms 2908 KB Output is correct
63 Correct 1 ms 2908 KB Output is correct
64 Correct 1 ms 2908 KB Output is correct
65 Correct 11 ms 2908 KB Output is correct
66 Correct 10 ms 3016 KB Output is correct
67 Correct 8 ms 2908 KB Output is correct
68 Correct 9 ms 2908 KB Output is correct
69 Correct 26 ms 2908 KB Output is correct
70 Correct 15 ms 2908 KB Output is correct
71 Correct 12 ms 2988 KB Output is correct
72 Correct 12 ms 2908 KB Output is correct
73 Correct 9 ms 2904 KB Output is correct
74 Correct 10 ms 2908 KB Output is correct
75 Correct 11 ms 2928 KB Output is correct
76 Correct 10 ms 2908 KB Output is correct
77 Correct 41 ms 3164 KB Output is correct
78 Correct 24 ms 3164 KB Output is correct
79 Correct 41 ms 3164 KB Output is correct
80 Correct 29 ms 3160 KB Output is correct
81 Correct 24 ms 3056 KB Output is correct
82 Correct 21 ms 3056 KB Output is correct
83 Correct 22 ms 3188 KB Output is correct
84 Correct 20 ms 3164 KB Output is correct
85 Correct 59 ms 3164 KB Output is correct
86 Correct 35 ms 3160 KB Output is correct
87 Correct 32 ms 3152 KB Output is correct
88 Correct 38 ms 3156 KB Output is correct
89 Correct 25 ms 3180 KB Output is correct
90 Correct 30 ms 3164 KB Output is correct
91 Correct 42 ms 3152 KB Output is correct
92 Correct 28 ms 3152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 0 ms 2908 KB Output is correct
3 Correct 0 ms 2908 KB Output is correct
4 Correct 0 ms 2908 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 1 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 0 ms 2908 KB Output is correct
10 Correct 0 ms 2908 KB Output is correct
11 Correct 0 ms 2908 KB Output is correct
12 Correct 0 ms 2908 KB Output is correct
13 Correct 0 ms 2908 KB Output is correct
14 Correct 0 ms 2908 KB Output is correct
15 Correct 0 ms 2908 KB Output is correct
16 Correct 0 ms 2908 KB Output is correct
17 Correct 0 ms 2908 KB Output is correct
18 Correct 0 ms 2908 KB Output is correct
19 Correct 1 ms 2908 KB Output is correct
20 Correct 0 ms 2908 KB Output is correct
21 Correct 0 ms 2908 KB Output is correct
22 Correct 1 ms 2908 KB Output is correct
23 Correct 1 ms 2908 KB Output is correct
24 Correct 0 ms 2908 KB Output is correct
25 Correct 0 ms 2908 KB Output is correct
26 Correct 0 ms 2908 KB Output is correct
27 Correct 1 ms 2908 KB Output is correct
28 Correct 0 ms 2908 KB Output is correct
29 Correct 1 ms 2904 KB Output is correct
30 Correct 1 ms 2908 KB Output is correct
31 Correct 0 ms 2908 KB Output is correct
32 Correct 1 ms 2908 KB Output is correct
33 Correct 0 ms 2908 KB Output is correct
34 Correct 1 ms 2908 KB Output is correct
35 Correct 1 ms 2908 KB Output is correct
36 Correct 1 ms 2908 KB Output is correct
37 Correct 0 ms 2868 KB Output is correct
38 Correct 0 ms 2908 KB Output is correct
39 Correct 0 ms 2908 KB Output is correct
40 Correct 1 ms 2904 KB Output is correct
41 Correct 1 ms 2908 KB Output is correct
42 Correct 0 ms 2908 KB Output is correct
43 Correct 0 ms 2908 KB Output is correct
44 Correct 1 ms 2908 KB Output is correct
45 Correct 1 ms 2908 KB Output is correct
46 Correct 1 ms 2908 KB Output is correct
47 Correct 1 ms 2908 KB Output is correct
48 Correct 1 ms 2908 KB Output is correct
49 Correct 1 ms 2908 KB Output is correct
50 Correct 1 ms 2908 KB Output is correct
51 Correct 0 ms 2908 KB Output is correct
52 Correct 1 ms 2908 KB Output is correct
53 Correct 1 ms 2904 KB Output is correct
54 Correct 1 ms 2908 KB Output is correct
55 Correct 1 ms 2908 KB Output is correct
56 Correct 1 ms 2908 KB Output is correct
57 Correct 1 ms 2904 KB Output is correct
58 Correct 1 ms 2908 KB Output is correct
59 Correct 1 ms 2908 KB Output is correct
60 Correct 0 ms 2908 KB Output is correct
61 Correct 1 ms 2908 KB Output is correct
62 Correct 1 ms 2908 KB Output is correct
63 Correct 1 ms 2908 KB Output is correct
64 Correct 1 ms 2908 KB Output is correct
65 Correct 11 ms 2908 KB Output is correct
66 Correct 10 ms 3016 KB Output is correct
67 Correct 8 ms 2908 KB Output is correct
68 Correct 9 ms 2908 KB Output is correct
69 Correct 26 ms 2908 KB Output is correct
70 Correct 15 ms 2908 KB Output is correct
71 Correct 12 ms 2988 KB Output is correct
72 Correct 12 ms 2908 KB Output is correct
73 Correct 9 ms 2904 KB Output is correct
74 Correct 10 ms 2908 KB Output is correct
75 Correct 11 ms 2928 KB Output is correct
76 Correct 10 ms 2908 KB Output is correct
77 Correct 41 ms 3164 KB Output is correct
78 Correct 24 ms 3164 KB Output is correct
79 Correct 41 ms 3164 KB Output is correct
80 Correct 29 ms 3160 KB Output is correct
81 Correct 24 ms 3056 KB Output is correct
82 Correct 21 ms 3056 KB Output is correct
83 Correct 22 ms 3188 KB Output is correct
84 Correct 20 ms 3164 KB Output is correct
85 Correct 59 ms 3164 KB Output is correct
86 Correct 35 ms 3160 KB Output is correct
87 Correct 32 ms 3152 KB Output is correct
88 Correct 38 ms 3156 KB Output is correct
89 Correct 25 ms 3180 KB Output is correct
90 Correct 30 ms 3164 KB Output is correct
91 Correct 42 ms 3152 KB Output is correct
92 Correct 28 ms 3152 KB Output is correct
93 Correct 775 ms 5048 KB Output is correct
94 Correct 801 ms 5160 KB Output is correct
95 Correct 788 ms 4944 KB Output is correct
96 Correct 656 ms 4712 KB Output is correct
97 Correct 639 ms 4720 KB Output is correct
98 Correct 710 ms 4852 KB Output is correct
99 Correct 85 ms 3356 KB Output is correct
100 Correct 77 ms 3412 KB Output is correct
101 Correct 76 ms 3316 KB Output is correct
102 Correct 62 ms 3412 KB Output is correct
103 Correct 473 ms 3772 KB Output is correct
104 Correct 280 ms 3808 KB Output is correct
105 Correct 247 ms 3692 KB Output is correct
106 Correct 205 ms 3920 KB Output is correct
107 Correct 1395 ms 4716 KB Output is correct
108 Correct 632 ms 4932 KB Output is correct
109 Correct 564 ms 4720 KB Output is correct
110 Correct 474 ms 4716 KB Output is correct
111 Correct 65 ms 3532 KB Output is correct
112 Correct 68 ms 3424 KB Output is correct
113 Correct 54 ms 3176 KB Output is correct
114 Correct 109 ms 3412 KB Output is correct
115 Correct 82 ms 3408 KB Output is correct
116 Correct 104 ms 3236 KB Output is correct
117 Correct 93 ms 3264 KB Output is correct
118 Correct 73 ms 3388 KB Output is correct
119 Correct 71 ms 3176 KB Output is correct
120 Correct 74 ms 3408 KB Output is correct
121 Correct 78 ms 3412 KB Output is correct
122 Correct 193 ms 3924 KB Output is correct
123 Correct 162 ms 3924 KB Output is correct
124 Correct 159 ms 3924 KB Output is correct
125 Correct 185 ms 3920 KB Output is correct
126 Correct 147 ms 3904 KB Output is correct
127 Correct 141 ms 3844 KB Output is correct
128 Correct 138 ms 3808 KB Output is correct
129 Correct 151 ms 3920 KB Output is correct
130 Correct 141 ms 3684 KB Output is correct
131 Correct 325 ms 3896 KB Output is correct
132 Correct 242 ms 3868 KB Output is correct
133 Correct 271 ms 3920 KB Output is correct
134 Correct 277 ms 3924 KB Output is correct
135 Correct 204 ms 3772 KB Output is correct
136 Correct 253 ms 3920 KB Output is correct
137 Correct 216 ms 3924 KB Output is correct
138 Correct 223 ms 3708 KB Output is correct
139 Correct 175 ms 3692 KB Output is correct
140 Correct 185 ms 3736 KB Output is correct
141 Correct 191 ms 3912 KB Output is correct
142 Correct 431 ms 4892 KB Output is correct
143 Correct 450 ms 4780 KB Output is correct
144 Correct 469 ms 4952 KB Output is correct
145 Correct 391 ms 4956 KB Output is correct
146 Correct 410 ms 4948 KB Output is correct
147 Correct 368 ms 4948 KB Output is correct
148 Correct 480 ms 4948 KB Output is correct
149 Correct 436 ms 4948 KB Output is correct
150 Correct 452 ms 4948 KB Output is correct
151 Correct 507 ms 4940 KB Output is correct
152 Correct 482 ms 4788 KB Output is correct
153 Correct 638 ms 4960 KB Output is correct
154 Correct 640 ms 4948 KB Output is correct
155 Correct 663 ms 4780 KB Output is correct
156 Correct 665 ms 4920 KB Output is correct
157 Correct 657 ms 4900 KB Output is correct
158 Correct 617 ms 4924 KB Output is correct
159 Correct 519 ms 4816 KB Output is correct
160 Correct 624 ms 4944 KB Output is correct
161 Correct 568 ms 4808 KB Output is correct
162 Correct 498 ms 4948 KB Output is correct
163 Correct 468 ms 4944 KB Output is correct
164 Correct 548 ms 4948 KB Output is correct
165 Correct 459 ms 4720 KB Output is correct
166 Correct 478 ms 4936 KB Output is correct
167 Correct 498 ms 4948 KB Output is correct