Submission #865952

# Submission time Handle Problem Language Result Execution time Memory
865952 2023-10-25T05:29:00 Z Requiem Amusement Park (CEOI19_amusementpark) C++17
100 / 100
1269 ms 3448 KB
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 998244353
#define INF 1e18
#define fi first
#define se second
#define endl "\n"
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define pi 3.14159265359
#define TASKNAME "amusepark"
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
const int MAXN = 3e2 + 9;
ii edge[MAXN];
int n,m,ans=0;
int pos[MAXN];
int prep[MAXN];
int N[MAXN];
void add(int &a,int b){
    a += b;
    if (a>=MOD) a-=MOD;
}
void sub(int &a,int b){
    a -= b;
    if (a < 0) a += MOD;
}
int dp[(1<<19)];
bool independent[(1<<19)];
int power(int a,int b){
    int res = 1;
    while(b>0){
        if (b&1) res = (res * a) %MOD;
        b>>=1;
        a = (a * a) % MOD;
    }
    return res;
}
main()
{
    fast;
   //  freopen(TASKNAME".inp","r",stdin);
   //  freopen(TASKNAME".out","w",stdout);
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>edge[i].fi>>edge[i].se;
//        edge[i].fi--;
//        edge[i].se--;
        N[edge[i].se-1] |= (1<<(edge[i].fi-1));
        N[edge[i].fi-1] |= (1<<(edge[i].se-1));
    }
    vector<int> bit;
    for(int i=1;i<(1<<n);i++){
        bit.clear();
        for(int j=0;j<n;j++){
            if (i&(1<<j)){
               bit.pb(j);
            }
        }
        independent[i] = true;
        for(int j=0;j<bit.size();j++){
            for(int k=0;k<bit.size();k++){
                if (N[bit[j]] & (1<<bit[k])){
                    independent[i] = false;
                }
            }
        }
    }
    dp[0] = 1;

    for(int i=1;i<(1<<n);i++){
        for(int j=i;j>0;j=(j-1)&i){
            int numbit = __builtin_popcount(j);
            if (independent[j]){
                if (numbit & 1) add(dp[i],dp[i^j]);
                else sub(dp[i],dp[i^j]);
            }
        }
    }
    cout<<((dp[(1<<n)-1] * m)%MOD * power(2,MOD-2))%MOD<<endl;
}

Compilation message

amusementpark.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   46 | main()
      | ^~~~
amusementpark.cpp: In function 'int main()':
amusementpark.cpp:68:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         for(int j=0;j<bit.size();j++){
      |                     ~^~~~~~~~~~~
amusementpark.cpp:69:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |             for(int k=0;k<bit.size();k++){
      |                         ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 0 ms 2508 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 0 ms 2508 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2508 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 0 ms 2508 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 0 ms 2512 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2516 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2648 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2508 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 2400 KB Output is correct
52 Correct 1 ms 2400 KB Output is correct
53 Correct 1 ms 2400 KB Output is correct
54 Correct 1 ms 2404 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 1 ms 2396 KB Output is correct
59 Correct 1 ms 2508 KB Output is correct
60 Correct 1 ms 2396 KB Output is correct
61 Correct 1 ms 2396 KB Output is correct
62 Correct 1 ms 2404 KB Output is correct
63 Correct 1 ms 2396 KB Output is correct
64 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 0 ms 2508 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2508 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 0 ms 2508 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 0 ms 2512 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2516 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2648 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2508 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 2400 KB Output is correct
52 Correct 1 ms 2400 KB Output is correct
53 Correct 1 ms 2400 KB Output is correct
54 Correct 1 ms 2404 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 1 ms 2396 KB Output is correct
59 Correct 1 ms 2508 KB Output is correct
60 Correct 1 ms 2396 KB Output is correct
61 Correct 1 ms 2396 KB Output is correct
62 Correct 1 ms 2404 KB Output is correct
63 Correct 1 ms 2396 KB Output is correct
64 Correct 1 ms 2396 KB Output is correct
65 Correct 19 ms 2540 KB Output is correct
66 Correct 20 ms 2536 KB Output is correct
67 Correct 19 ms 2540 KB Output is correct
68 Correct 16 ms 2396 KB Output is correct
69 Correct 17 ms 2396 KB Output is correct
70 Correct 21 ms 2788 KB Output is correct
71 Correct 16 ms 2396 KB Output is correct
72 Correct 15 ms 2536 KB Output is correct
73 Correct 17 ms 2396 KB Output is correct
74 Correct 16 ms 2528 KB Output is correct
75 Correct 15 ms 2536 KB Output is correct
76 Correct 14 ms 2544 KB Output is correct
77 Correct 57 ms 2396 KB Output is correct
78 Correct 63 ms 2396 KB Output is correct
79 Correct 52 ms 2392 KB Output is correct
80 Correct 58 ms 2392 KB Output is correct
81 Correct 50 ms 2544 KB Output is correct
82 Correct 49 ms 2532 KB Output is correct
83 Correct 44 ms 2540 KB Output is correct
84 Correct 48 ms 2536 KB Output is correct
85 Correct 48 ms 2396 KB Output is correct
86 Correct 50 ms 2392 KB Output is correct
87 Correct 45 ms 2396 KB Output is correct
88 Correct 44 ms 2396 KB Output is correct
89 Correct 48 ms 2528 KB Output is correct
90 Correct 45 ms 2648 KB Output is correct
91 Correct 45 ms 2396 KB Output is correct
92 Correct 39 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 0 ms 2508 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2508 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 0 ms 2508 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 0 ms 2512 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2516 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2648 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2508 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 2400 KB Output is correct
52 Correct 1 ms 2400 KB Output is correct
53 Correct 1 ms 2400 KB Output is correct
54 Correct 1 ms 2404 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 1 ms 2396 KB Output is correct
59 Correct 1 ms 2508 KB Output is correct
60 Correct 1 ms 2396 KB Output is correct
61 Correct 1 ms 2396 KB Output is correct
62 Correct 1 ms 2404 KB Output is correct
63 Correct 1 ms 2396 KB Output is correct
64 Correct 1 ms 2396 KB Output is correct
65 Correct 19 ms 2540 KB Output is correct
66 Correct 20 ms 2536 KB Output is correct
67 Correct 19 ms 2540 KB Output is correct
68 Correct 16 ms 2396 KB Output is correct
69 Correct 17 ms 2396 KB Output is correct
70 Correct 21 ms 2788 KB Output is correct
71 Correct 16 ms 2396 KB Output is correct
72 Correct 15 ms 2536 KB Output is correct
73 Correct 17 ms 2396 KB Output is correct
74 Correct 16 ms 2528 KB Output is correct
75 Correct 15 ms 2536 KB Output is correct
76 Correct 14 ms 2544 KB Output is correct
77 Correct 57 ms 2396 KB Output is correct
78 Correct 63 ms 2396 KB Output is correct
79 Correct 52 ms 2392 KB Output is correct
80 Correct 58 ms 2392 KB Output is correct
81 Correct 50 ms 2544 KB Output is correct
82 Correct 49 ms 2532 KB Output is correct
83 Correct 44 ms 2540 KB Output is correct
84 Correct 48 ms 2536 KB Output is correct
85 Correct 48 ms 2396 KB Output is correct
86 Correct 50 ms 2392 KB Output is correct
87 Correct 45 ms 2396 KB Output is correct
88 Correct 44 ms 2396 KB Output is correct
89 Correct 48 ms 2528 KB Output is correct
90 Correct 45 ms 2648 KB Output is correct
91 Correct 45 ms 2396 KB Output is correct
92 Correct 39 ms 2392 KB Output is correct
93 Correct 1231 ms 3340 KB Output is correct
94 Correct 1197 ms 2872 KB Output is correct
95 Correct 1242 ms 3012 KB Output is correct
96 Correct 1269 ms 2928 KB Output is correct
97 Correct 1190 ms 3012 KB Output is correct
98 Correct 1234 ms 2896 KB Output is correct
99 Correct 154 ms 2392 KB Output is correct
100 Correct 150 ms 2388 KB Output is correct
101 Correct 177 ms 2396 KB Output is correct
102 Correct 145 ms 2396 KB Output is correct
103 Correct 411 ms 2620 KB Output is correct
104 Correct 402 ms 2392 KB Output is correct
105 Correct 448 ms 2644 KB Output is correct
106 Correct 410 ms 2388 KB Output is correct
107 Correct 1241 ms 3196 KB Output is correct
108 Correct 1200 ms 2928 KB Output is correct
109 Correct 1203 ms 2932 KB Output is correct
110 Correct 1162 ms 3180 KB Output is correct
111 Correct 139 ms 2544 KB Output is correct
112 Correct 154 ms 2384 KB Output is correct
113 Correct 124 ms 2564 KB Output is correct
114 Correct 140 ms 2564 KB Output is correct
115 Correct 136 ms 2396 KB Output is correct
116 Correct 134 ms 2564 KB Output is correct
117 Correct 116 ms 2564 KB Output is correct
118 Correct 140 ms 2560 KB Output is correct
119 Correct 134 ms 2396 KB Output is correct
120 Correct 127 ms 2564 KB Output is correct
121 Correct 113 ms 2396 KB Output is correct
122 Correct 422 ms 2384 KB Output is correct
123 Correct 411 ms 2628 KB Output is correct
124 Correct 386 ms 2616 KB Output is correct
125 Correct 365 ms 2644 KB Output is correct
126 Correct 364 ms 2544 KB Output is correct
127 Correct 332 ms 2624 KB Output is correct
128 Correct 348 ms 2388 KB Output is correct
129 Correct 327 ms 2632 KB Output is correct
130 Correct 335 ms 2652 KB Output is correct
131 Correct 408 ms 2388 KB Output is correct
132 Correct 405 ms 2384 KB Output is correct
133 Correct 387 ms 2396 KB Output is correct
134 Correct 350 ms 2392 KB Output is correct
135 Correct 416 ms 2648 KB Output is correct
136 Correct 381 ms 2652 KB Output is correct
137 Correct 375 ms 2640 KB Output is correct
138 Correct 332 ms 2388 KB Output is correct
139 Correct 413 ms 2628 KB Output is correct
140 Correct 393 ms 2632 KB Output is correct
141 Correct 320 ms 2624 KB Output is correct
142 Correct 1140 ms 3136 KB Output is correct
143 Correct 1112 ms 2932 KB Output is correct
144 Correct 1016 ms 3152 KB Output is correct
145 Correct 1035 ms 2996 KB Output is correct
146 Correct 1046 ms 2896 KB Output is correct
147 Correct 951 ms 2900 KB Output is correct
148 Correct 1146 ms 2996 KB Output is correct
149 Correct 1138 ms 2928 KB Output is correct
150 Correct 1139 ms 3188 KB Output is correct
151 Correct 1075 ms 3204 KB Output is correct
152 Correct 1051 ms 2936 KB Output is correct
153 Correct 1228 ms 2932 KB Output is correct
154 Correct 1219 ms 3368 KB Output is correct
155 Correct 1164 ms 3016 KB Output is correct
156 Correct 992 ms 2932 KB Output is correct
157 Correct 1159 ms 2932 KB Output is correct
158 Correct 1116 ms 3320 KB Output is correct
159 Correct 1199 ms 3188 KB Output is correct
160 Correct 1100 ms 2932 KB Output is correct
161 Correct 895 ms 2900 KB Output is correct
162 Correct 1175 ms 3256 KB Output is correct
163 Correct 1130 ms 3220 KB Output is correct
164 Correct 1113 ms 3012 KB Output is correct
165 Correct 1080 ms 2936 KB Output is correct
166 Correct 1062 ms 2988 KB Output is correct
167 Correct 1010 ms 3448 KB Output is correct