답안 #781711

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781711 2023-07-13T10:19:39 Z magician Amusement Park (CEOI19_amusementpark) C++14
7 / 100
1 ms 324 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);
                        vector<int> root;
                        for(int i = 0; i < N; i++) {
                                for(int j = 0; j < N; j++) {
                                        if(BIT(new_adj[i], j)) {
                                                vis[j] = 1;
                                        }
                                }
                        }
                        for(int i = 0; i < N; i++) {
                                if(vis[i] == 0) {
                                        root.push_back(i);
                                }
                                else {
                                        vis[i] = 0;
                                }
                        }
                        function<void(int)> dfs;
                        bool good = !root.empty();
                        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)) {
                                                dfs(i);
                                                if(!good)
                                                        return;
                                        }
                                }
                                vis[u] = 2;
                        };
                        for(int i : root)
                                dfs(i);
                        if(good && root.size())
                                (ans += __builtin_popcount(mask)) %= MOD;
                }
                cout << ans;
        }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 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 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 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 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Incorrect 1 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 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 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Incorrect 1 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 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 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Incorrect 1 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 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 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Incorrect 1 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -