Submission #782056

# Submission time Handle Problem Language Result Execution time Memory
782056 2023-07-13T15:10:09 Z magician Amusement Park (CEOI19_amusementpark) C++14
19 / 100
3000 ms 340 KB
#include<bits/stdc++.h>
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
using namespace std;

const int MAXN = 18;
const int MOD = 998244353;
int N, M;
int adj[MAXN];
vector<pair<int, int>> e;

int main() {
        ios::sync_with_stdio(0);
        cin.tie(0);

        cin >> N >> M;
        for(int i = 0; i < M; i++) {
                int a, b;
                cin >> a >> b;
                a--;
                b--;
                adj[a] ^= MASK(b);
                e.push_back(make_pair(a, b));
        }

        //if(M <= 20)
        {
                int ans = 0;
                for(int mask = 0; mask < MASK(M); mask++) {
                        vector<int> new_adj(N, 0);
                        for(int i = 0; i < M; i++) {
                                if(BIT(mask, i))
                                        new_adj[e[i].second] ^= MASK(e[i].first);
                                else
                                        new_adj[e[i].first] ^= MASK(e[i].second);
                        }
                        vector<int> vis(N, 0);
                        bool good = true;
                        function<void(int)> dfs;
                        dfs = [&](int u) {
                                if(!good)
                                        return;
                                vis[u] = 1;
                                for(int i = 0; i < N; i++) {
                                        if(BIT(new_adj[u], i) && vis[i] == 1) {
                                                good = false;
                                                return;
                                        }
                                }
                                for(int i = 0; i < N; i++) {
                                        if(BIT(new_adj[u], i) && vis[i] == 0) {
                                                dfs(i);
                                                if(!good)
                                                        return;
                                        }
                                }
                                vis[u] = 2;
                        };
                        for(int i = 0; i < N; i++)
                                if(vis[i] == 0)
                                        dfs(i);
                        if(good)
                                (ans += __builtin_popcount(mask)) %= MOD;
                }
                cout << ans;
        }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 248 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 2 ms 212 KB Output is correct
24 Correct 9 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 248 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 2 ms 212 KB Output is correct
24 Correct 9 ms 212 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 7 ms 212 KB Output is correct
30 Correct 54 ms 312 KB Output is correct
31 Correct 389 ms 296 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 2 ms 320 KB Output is correct
35 Correct 19 ms 316 KB Output is correct
36 Correct 205 ms 212 KB Output is correct
37 Execution timed out 3083 ms 212 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 248 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 2 ms 212 KB Output is correct
24 Correct 9 ms 212 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 7 ms 212 KB Output is correct
30 Correct 54 ms 312 KB Output is correct
31 Correct 389 ms 296 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 2 ms 320 KB Output is correct
35 Correct 19 ms 316 KB Output is correct
36 Correct 205 ms 212 KB Output is correct
37 Execution timed out 3083 ms 212 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 248 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 2 ms 212 KB Output is correct
24 Correct 9 ms 212 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 7 ms 212 KB Output is correct
30 Correct 54 ms 312 KB Output is correct
31 Correct 389 ms 296 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 2 ms 320 KB Output is correct
35 Correct 19 ms 316 KB Output is correct
36 Correct 205 ms 212 KB Output is correct
37 Execution timed out 3083 ms 212 KB Time limit exceeded
38 Halted 0 ms 0 KB -