Submission #1048796

# Submission time Handle Problem Language Result Execution time Memory
1048796 2024-08-08T09:34:28 Z anton Amusement Park (CEOI19_amusementpark) C++17
42 / 100
3000 ms 161948 KB
#include<bits/stdc++.h>

using namespace std;

#define int long long
#define pii pair<int, int>
int N, M;
const int MOD = 998244353;
struct Edge{
    int sides[2];
    int dir= 0;
    Edge(){};
    Edge(int a, int b){
        sides[0] = a;
        sides[1] =b;
    }
    int dest(){
        return sides[dir];
    }
    int origin(){
        return sides[dir^1];
    }
};

vector<vector<int>> adj;
vector<Edge> edges; 


vector<int> ch(int i){
    vector<int> res;
    for(auto eid : adj[i]){
        Edge edge= edges[eid];
        if(i == edge.origin()){
            res.push_back(edge.dest());
        }
    }
    return res;
}

bool is_DAG(int mask){
    for(int i = 0; i<M; i++){
        edges[i].dir = (mask>>i)& 1;
    }
    vector<int> free;
    vector<int> in_deg(N);
    for(int i = 0; i<N; i++){
        for(auto c: ch(i)){
            in_deg[c]++;
        }
    }
    for(int i = 0; i<N; i++){
        if(in_deg[i]==0){
            free.push_back(i);
        }
    }

    while(free.size()>0){
        int i = free.back();
        free.pop_back();
        for(auto c: ch(i)){
            in_deg[c]--;
            if(in_deg[c]==0){
                free.push_back(c);
            }
        }
    }

    for(int i = 0; i<N; i++){
        if(in_deg[i]>0){
            return false;
        }
    }
    return true;
}

int get_mask(vector<int>& order){
    int res = 0;
    for(int i = 0; i<M; i++){
        Edge e= edges[i];
        if(order[e.sides[0]]>order[e.sides[1]]){
            res |= (1LL<<i);
        }
    }
    return res;
}
unordered_set<int> get_valid_masks(){
    vector<int> order;
    for(int i = 0; i<N; i++){
        order.push_back(i);
    }
    bool ok = true;
    unordered_set<int> masks;
    while(ok){
        masks.insert(get_mask(order));
        ok = next_permutation(order.begin(), order.end());
    }
    return masks;
}

int count_bits(int v){
    if(v==0){
        return 0;
    }
    return (v&1) + count_bits((v>>1));
}
signed main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);

    cin>>N>>M;

    adj.resize(N);

    for(int i = 0; i<M; i++){
        int a, b;
        cin>>a>>b;
        a--;b--;
        edges.push_back(Edge(a, b));
        adj[a].push_back(i);
        adj[b].push_back(i);
    }

    int RES =0;
    for(auto mask: get_valid_masks()){
        //cout<<bitset<3>(mask)<<endl;
        RES = (RES + count_bits(mask));
    }

    cout<<RES<<endl;

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 2 ms 348 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 3 ms 992 KB Output is correct
37 Correct 7 ms 1464 KB Output is correct
38 Correct 7 ms 1976 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 4 ms 344 KB Output is correct
41 Correct 8 ms 344 KB Output is correct
42 Correct 9 ms 600 KB Output is correct
43 Correct 17 ms 1464 KB Output is correct
44 Correct 24 ms 2680 KB Output is correct
45 Correct 37 ms 5252 KB Output is correct
46 Correct 63 ms 10012 KB Output is correct
47 Correct 83 ms 19620 KB Output is correct
48 Correct 3 ms 348 KB Output is correct
49 Correct 6 ms 592 KB Output is correct
50 Correct 7 ms 604 KB Output is correct
51 Correct 8 ms 604 KB Output is correct
52 Correct 24 ms 464 KB Output is correct
53 Correct 44 ms 348 KB Output is correct
54 Correct 77 ms 712 KB Output is correct
55 Correct 150 ms 1764 KB Output is correct
56 Correct 185 ms 9884 KB Output is correct
57 Correct 402 ms 20856 KB Output is correct
58 Correct 622 ms 43752 KB Output is correct
59 Correct 1166 ms 86236 KB Output is correct
60 Correct 2187 ms 161948 KB Output is correct
61 Correct 45 ms 452 KB Output is correct
62 Correct 64 ms 772 KB Output is correct
63 Correct 83 ms 820 KB Output is correct
64 Correct 103 ms 784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 2 ms 348 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 3 ms 992 KB Output is correct
37 Correct 7 ms 1464 KB Output is correct
38 Correct 7 ms 1976 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 4 ms 344 KB Output is correct
41 Correct 8 ms 344 KB Output is correct
42 Correct 9 ms 600 KB Output is correct
43 Correct 17 ms 1464 KB Output is correct
44 Correct 24 ms 2680 KB Output is correct
45 Correct 37 ms 5252 KB Output is correct
46 Correct 63 ms 10012 KB Output is correct
47 Correct 83 ms 19620 KB Output is correct
48 Correct 3 ms 348 KB Output is correct
49 Correct 6 ms 592 KB Output is correct
50 Correct 7 ms 604 KB Output is correct
51 Correct 8 ms 604 KB Output is correct
52 Correct 24 ms 464 KB Output is correct
53 Correct 44 ms 348 KB Output is correct
54 Correct 77 ms 712 KB Output is correct
55 Correct 150 ms 1764 KB Output is correct
56 Correct 185 ms 9884 KB Output is correct
57 Correct 402 ms 20856 KB Output is correct
58 Correct 622 ms 43752 KB Output is correct
59 Correct 1166 ms 86236 KB Output is correct
60 Correct 2187 ms 161948 KB Output is correct
61 Correct 45 ms 452 KB Output is correct
62 Correct 64 ms 772 KB Output is correct
63 Correct 83 ms 820 KB Output is correct
64 Correct 103 ms 784 KB Output is correct
65 Execution timed out 3045 ms 9884 KB Time limit exceeded
66 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 2 ms 348 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 3 ms 992 KB Output is correct
37 Correct 7 ms 1464 KB Output is correct
38 Correct 7 ms 1976 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 4 ms 344 KB Output is correct
41 Correct 8 ms 344 KB Output is correct
42 Correct 9 ms 600 KB Output is correct
43 Correct 17 ms 1464 KB Output is correct
44 Correct 24 ms 2680 KB Output is correct
45 Correct 37 ms 5252 KB Output is correct
46 Correct 63 ms 10012 KB Output is correct
47 Correct 83 ms 19620 KB Output is correct
48 Correct 3 ms 348 KB Output is correct
49 Correct 6 ms 592 KB Output is correct
50 Correct 7 ms 604 KB Output is correct
51 Correct 8 ms 604 KB Output is correct
52 Correct 24 ms 464 KB Output is correct
53 Correct 44 ms 348 KB Output is correct
54 Correct 77 ms 712 KB Output is correct
55 Correct 150 ms 1764 KB Output is correct
56 Correct 185 ms 9884 KB Output is correct
57 Correct 402 ms 20856 KB Output is correct
58 Correct 622 ms 43752 KB Output is correct
59 Correct 1166 ms 86236 KB Output is correct
60 Correct 2187 ms 161948 KB Output is correct
61 Correct 45 ms 452 KB Output is correct
62 Correct 64 ms 772 KB Output is correct
63 Correct 83 ms 820 KB Output is correct
64 Correct 103 ms 784 KB Output is correct
65 Execution timed out 3045 ms 9884 KB Time limit exceeded
66 Halted 0 ms 0 KB -