Submission #486712

# Submission time Handle Problem Language Result Execution time Memory
486712 2021-11-12T13:02:20 Z XII Amusement Park (CEOI19_amusementpark) C++17
100 / 100
263 ms 39412 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define ALL(x) (x).begin(), (x).end()

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORU(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

#define IOS cin.tie(0)->sync_with_stdio(false);
#define PROB "CEOI19_amusementpark"
void Fi(){
    if(fopen(PROB".inp", "r")){
        freopen(PROB".inp", "r", stdin);
        freopen(PROB".out", "w", stdout);
    }
}

const int N = 18;
const int MOD = 998244353;
int n, m;
int edge[N * N];

int f[1 << N][N + 1]; /// number of not connected graph
int dp[1 << N][N + 1]; /// number of graph

bool noEdge(const int &mask){
    FOR(i, 0, m) if((mask & edge[i]) == edge[i]) return false;
    return true;
}

void addto(int &a, const int &b){
    a = (a + b >= MOD ? a + b - MOD : a + b);
}

void delto(int &a, const int &b){
    a = (a - b < 0 ? a - b + MOD : a - b);
}

int mul(const int &a, const int &b){
    return (1LL * a * b) % MOD;
}

int powmod(int a, int b){
    int ans = 1;
    for(; b > 0; b >>= 1){
        if(b & 1) ans = mul(ans, a);
        a = mul(a, a);
    }
    return ans;
}

int main(){
    IOS;
    Fi();
    cin >> n >> m;
    FOR(i, 0, m){
        int u, v; cin >> u >> v;
        --u, --v;
        edge[i] = (1 << u) | (1 << v);
    }
    FOR(mask, 0, 1 << n) if(noEdge(mask)){
        int nbit = __builtin_popcount(mask);
        f[mask][nbit] = ((nbit & 1) ? MOD - 1 : 1);
//        cout << mask << " " << nbit << " " << f[mask][nbit] << "\n";
    }

    for(int i = 1; i < (1 << n); i <<= 1){ /// can remove bit 0...(log2(i))
        for(int j = 0; j < (1 << n); j += (i << 1)){
            FOR(k, 0, i){
                FORU(p, 0, n) addto(f[j | i | k][p], f[j | k][p]);
            }
        }
    }

    FOR(mask, 0, 1 << n){
//        int tmp = dp[mask][0] = pow(f[mask][0], MOD - 2);
        dp[mask][0] = f[mask][0];
        FORU(i, 1, n){
            FOR(j, 0, i){
                delto(dp[mask][i], mul(dp[mask][j], f[mask][i - j]));
//                dp[mask][i] = mul(dp[mask][i], tmp);
            }
        }
    }

    for(int i = 1; i < (1 << n); i <<= 1){
        for(int j = 0; j < (1 << n); j += (i << 1)){
            FOR(k, 0, i){
                FORU(p, 0, n) delto(dp[j | i | k][p], dp[j | k][p]);
            }
        }
    }

    int ans = dp[(1 << n) - 1][n];
    ans = mul(ans, m);
    ans = mul(ans, (MOD + 1) / 2); /// devide by 2
    cout << ans;

    return 0;
}

Compilation message

amusementpark.cpp: In function 'void Fi()':
amusementpark.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen(PROB".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
amusementpark.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(PROB".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 456 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 456 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 1 ms 324 KB Output is correct
33 Correct 1 ms 324 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 328 KB Output is correct
41 Correct 0 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 320 KB Output is correct
48 Correct 1 ms 328 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 460 KB Output is correct
53 Correct 1 ms 460 KB Output is correct
54 Correct 1 ms 460 KB Output is correct
55 Correct 1 ms 460 KB Output is correct
56 Correct 1 ms 460 KB Output is correct
57 Correct 1 ms 460 KB Output is correct
58 Correct 1 ms 460 KB Output is correct
59 Correct 1 ms 460 KB Output is correct
60 Correct 1 ms 460 KB Output is correct
61 Correct 1 ms 460 KB Output is correct
62 Correct 1 ms 460 KB Output is correct
63 Correct 1 ms 460 KB Output is correct
64 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 456 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 1 ms 324 KB Output is correct
33 Correct 1 ms 324 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 328 KB Output is correct
41 Correct 0 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 320 KB Output is correct
48 Correct 1 ms 328 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 460 KB Output is correct
53 Correct 1 ms 460 KB Output is correct
54 Correct 1 ms 460 KB Output is correct
55 Correct 1 ms 460 KB Output is correct
56 Correct 1 ms 460 KB Output is correct
57 Correct 1 ms 460 KB Output is correct
58 Correct 1 ms 460 KB Output is correct
59 Correct 1 ms 460 KB Output is correct
60 Correct 1 ms 460 KB Output is correct
61 Correct 1 ms 460 KB Output is correct
62 Correct 1 ms 460 KB Output is correct
63 Correct 1 ms 460 KB Output is correct
64 Correct 1 ms 460 KB Output is correct
65 Correct 10 ms 2764 KB Output is correct
66 Correct 9 ms 2764 KB Output is correct
67 Correct 11 ms 2764 KB Output is correct
68 Correct 10 ms 2764 KB Output is correct
69 Correct 10 ms 2756 KB Output is correct
70 Correct 10 ms 2764 KB Output is correct
71 Correct 10 ms 2752 KB Output is correct
72 Correct 10 ms 2736 KB Output is correct
73 Correct 10 ms 2764 KB Output is correct
74 Correct 10 ms 2768 KB Output is correct
75 Correct 9 ms 2764 KB Output is correct
76 Correct 9 ms 2764 KB Output is correct
77 Correct 21 ms 5152 KB Output is correct
78 Correct 24 ms 5164 KB Output is correct
79 Correct 21 ms 5196 KB Output is correct
80 Correct 22 ms 5232 KB Output is correct
81 Correct 20 ms 5196 KB Output is correct
82 Correct 21 ms 5128 KB Output is correct
83 Correct 22 ms 5188 KB Output is correct
84 Correct 21 ms 5188 KB Output is correct
85 Correct 22 ms 5160 KB Output is correct
86 Correct 23 ms 5196 KB Output is correct
87 Correct 21 ms 5208 KB Output is correct
88 Correct 21 ms 5196 KB Output is correct
89 Correct 21 ms 5188 KB Output is correct
90 Correct 21 ms 5208 KB Output is correct
91 Correct 22 ms 5164 KB Output is correct
92 Correct 21 ms 5204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 456 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 1 ms 324 KB Output is correct
33 Correct 1 ms 324 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 328 KB Output is correct
41 Correct 0 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 320 KB Output is correct
48 Correct 1 ms 328 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 1 ms 460 KB Output is correct
53 Correct 1 ms 460 KB Output is correct
54 Correct 1 ms 460 KB Output is correct
55 Correct 1 ms 460 KB Output is correct
56 Correct 1 ms 460 KB Output is correct
57 Correct 1 ms 460 KB Output is correct
58 Correct 1 ms 460 KB Output is correct
59 Correct 1 ms 460 KB Output is correct
60 Correct 1 ms 460 KB Output is correct
61 Correct 1 ms 460 KB Output is correct
62 Correct 1 ms 460 KB Output is correct
63 Correct 1 ms 460 KB Output is correct
64 Correct 1 ms 460 KB Output is correct
65 Correct 10 ms 2764 KB Output is correct
66 Correct 9 ms 2764 KB Output is correct
67 Correct 11 ms 2764 KB Output is correct
68 Correct 10 ms 2764 KB Output is correct
69 Correct 10 ms 2756 KB Output is correct
70 Correct 10 ms 2764 KB Output is correct
71 Correct 10 ms 2752 KB Output is correct
72 Correct 10 ms 2736 KB Output is correct
73 Correct 10 ms 2764 KB Output is correct
74 Correct 10 ms 2768 KB Output is correct
75 Correct 9 ms 2764 KB Output is correct
76 Correct 9 ms 2764 KB Output is correct
77 Correct 21 ms 5152 KB Output is correct
78 Correct 24 ms 5164 KB Output is correct
79 Correct 21 ms 5196 KB Output is correct
80 Correct 22 ms 5232 KB Output is correct
81 Correct 20 ms 5196 KB Output is correct
82 Correct 21 ms 5128 KB Output is correct
83 Correct 22 ms 5188 KB Output is correct
84 Correct 21 ms 5188 KB Output is correct
85 Correct 22 ms 5160 KB Output is correct
86 Correct 23 ms 5196 KB Output is correct
87 Correct 21 ms 5208 KB Output is correct
88 Correct 21 ms 5196 KB Output is correct
89 Correct 21 ms 5188 KB Output is correct
90 Correct 21 ms 5208 KB Output is correct
91 Correct 22 ms 5164 KB Output is correct
92 Correct 21 ms 5204 KB Output is correct
93 Correct 239 ms 39236 KB Output is correct
94 Correct 237 ms 39236 KB Output is correct
95 Correct 244 ms 39264 KB Output is correct
96 Correct 229 ms 39236 KB Output is correct
97 Correct 238 ms 39240 KB Output is correct
98 Correct 237 ms 39236 KB Output is correct
99 Correct 46 ms 9960 KB Output is correct
100 Correct 45 ms 9964 KB Output is correct
101 Correct 46 ms 10052 KB Output is correct
102 Correct 48 ms 10016 KB Output is correct
103 Correct 107 ms 19784 KB Output is correct
104 Correct 109 ms 19780 KB Output is correct
105 Correct 113 ms 19808 KB Output is correct
106 Correct 111 ms 19800 KB Output is correct
107 Correct 236 ms 39260 KB Output is correct
108 Correct 263 ms 39412 KB Output is correct
109 Correct 247 ms 39236 KB Output is correct
110 Correct 244 ms 39228 KB Output is correct
111 Correct 54 ms 10056 KB Output is correct
112 Correct 48 ms 10032 KB Output is correct
113 Correct 50 ms 10072 KB Output is correct
114 Correct 47 ms 10052 KB Output is correct
115 Correct 50 ms 9972 KB Output is correct
116 Correct 46 ms 10052 KB Output is correct
117 Correct 49 ms 10056 KB Output is correct
118 Correct 48 ms 10044 KB Output is correct
119 Correct 55 ms 10032 KB Output is correct
120 Correct 46 ms 10048 KB Output is correct
121 Correct 49 ms 10052 KB Output is correct
122 Correct 112 ms 19800 KB Output is correct
123 Correct 106 ms 19780 KB Output is correct
124 Correct 108 ms 19772 KB Output is correct
125 Correct 113 ms 19800 KB Output is correct
126 Correct 113 ms 19924 KB Output is correct
127 Correct 110 ms 19812 KB Output is correct
128 Correct 109 ms 19796 KB Output is correct
129 Correct 106 ms 19736 KB Output is correct
130 Correct 112 ms 19800 KB Output is correct
131 Correct 109 ms 19796 KB Output is correct
132 Correct 107 ms 19780 KB Output is correct
133 Correct 106 ms 19780 KB Output is correct
134 Correct 109 ms 19800 KB Output is correct
135 Correct 103 ms 19800 KB Output is correct
136 Correct 117 ms 19800 KB Output is correct
137 Correct 113 ms 19788 KB Output is correct
138 Correct 109 ms 19804 KB Output is correct
139 Correct 113 ms 19780 KB Output is correct
140 Correct 121 ms 19800 KB Output is correct
141 Correct 124 ms 19768 KB Output is correct
142 Correct 240 ms 39260 KB Output is correct
143 Correct 244 ms 39328 KB Output is correct
144 Correct 249 ms 39392 KB Output is correct
145 Correct 235 ms 39184 KB Output is correct
146 Correct 253 ms 39208 KB Output is correct
147 Correct 241 ms 39248 KB Output is correct
148 Correct 243 ms 39236 KB Output is correct
149 Correct 242 ms 39236 KB Output is correct
150 Correct 244 ms 39236 KB Output is correct
151 Correct 239 ms 39284 KB Output is correct
152 Correct 248 ms 39264 KB Output is correct
153 Correct 235 ms 39252 KB Output is correct
154 Correct 233 ms 39236 KB Output is correct
155 Correct 246 ms 39236 KB Output is correct
156 Correct 245 ms 39236 KB Output is correct
157 Correct 243 ms 39260 KB Output is correct
158 Correct 246 ms 39392 KB Output is correct
159 Correct 232 ms 39236 KB Output is correct
160 Correct 239 ms 39236 KB Output is correct
161 Correct 249 ms 39252 KB Output is correct
162 Correct 241 ms 39172 KB Output is correct
163 Correct 242 ms 39268 KB Output is correct
164 Correct 245 ms 39364 KB Output is correct
165 Correct 242 ms 39240 KB Output is correct
166 Correct 258 ms 39308 KB Output is correct
167 Correct 244 ms 39260 KB Output is correct