Submission #1048783

# Submission time Handle Problem Language Result Execution time Memory
1048783 2024-08-08T09:32:18 Z anton Amusement Park (CEOI19_amusementpark) C++17
19 / 100
94 ms 19584 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;
}
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 + __builtin_popcount(mask));
        
    }

    cout<<RES<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 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 0 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 0 ms 344 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 0 ms 348 KB Output is correct
21 Correct 0 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 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 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 0 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 0 ms 344 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 0 ms 348 KB Output is correct
21 Correct 0 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 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 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 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 3 ms 860 KB Output is correct
37 Correct 7 ms 1548 KB Output is correct
38 Correct 7 ms 1972 KB Output is correct
39 Correct 3 ms 348 KB Output is correct
40 Correct 5 ms 456 KB Output is correct
41 Correct 8 ms 348 KB Output is correct
42 Correct 10 ms 604 KB Output is correct
43 Correct 18 ms 1620 KB Output is correct
44 Correct 24 ms 2664 KB Output is correct
45 Correct 37 ms 5412 KB Output is correct
46 Correct 55 ms 10128 KB Output is correct
47 Incorrect 94 ms 19584 KB Output isn't correct
48 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 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 0 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 0 ms 344 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 0 ms 348 KB Output is correct
21 Correct 0 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 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 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 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 3 ms 860 KB Output is correct
37 Correct 7 ms 1548 KB Output is correct
38 Correct 7 ms 1972 KB Output is correct
39 Correct 3 ms 348 KB Output is correct
40 Correct 5 ms 456 KB Output is correct
41 Correct 8 ms 348 KB Output is correct
42 Correct 10 ms 604 KB Output is correct
43 Correct 18 ms 1620 KB Output is correct
44 Correct 24 ms 2664 KB Output is correct
45 Correct 37 ms 5412 KB Output is correct
46 Correct 55 ms 10128 KB Output is correct
47 Incorrect 94 ms 19584 KB Output isn't correct
48 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 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 0 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 0 ms 344 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 0 ms 348 KB Output is correct
21 Correct 0 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 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 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 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 3 ms 860 KB Output is correct
37 Correct 7 ms 1548 KB Output is correct
38 Correct 7 ms 1972 KB Output is correct
39 Correct 3 ms 348 KB Output is correct
40 Correct 5 ms 456 KB Output is correct
41 Correct 8 ms 348 KB Output is correct
42 Correct 10 ms 604 KB Output is correct
43 Correct 18 ms 1620 KB Output is correct
44 Correct 24 ms 2664 KB Output is correct
45 Correct 37 ms 5412 KB Output is correct
46 Correct 55 ms 10128 KB Output is correct
47 Incorrect 94 ms 19584 KB Output isn't correct
48 Halted 0 ms 0 KB -