Submission #1052453

# Submission time Handle Problem Language Result Execution time Memory
1052453 2024-08-10T14:41:05 Z handlename Amusement Park (CEOI19_amusementpark) C++17
42 / 100
309 ms 3408 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define float long double
// const int MOD=1e9+7;
const int MOD=998244353;
const int sqn=450;
const long double eps=1e-6;
const int dx[4]={0,0,1,-1};
const int dy[4]={1,-1,0,0};
long long power(long long a,long long b,long long p=MOD){
    long long res=1;
    while (b>0){
        if (b%2==1) res=(res*a)%p;
        b/=2;
        a=(a*a)%p;
    }
    return res;
}
int n,m;
bool adj[20][20],indep[1000001];
// for each legal proposal, reversing the edges creates another
// costs for this pair is m
// sum of costs is m * DAGCount/2
// where DAGCount = number of DAGs on original graph
long long dp[1000001];
// dp[mask] = number of DAGs on graph with mask vertices
// for any DAG, at least 1 vertex has out degree 0
// we loop through all possible subsets of vertices with out degree 0
// this subset must be an independent set
// however, we cannot just add them all up
// as subsets of independent sets are also independent
// to fix double counting, use PIE
void runtc(){
    cin>>n>>m;
    for (int i=1;i<=m;i++){
        int u,v;
        cin>>u>>v;
        u--;
        v--;
        adj[u][v]=adj[v][u]=true;
    }
    memset(indep,true,sizeof(indep));
    for (int i=0;i<(1<<n);i++){
        for (int j=0;j<n;j++){
            for (int k=j+1;k<n;k++){
                if (!(i&(1<<j))) continue;
                if (!(i&(1<<k))) continue;
                if (adj[j][k]) indep[i]=false;
            }
        }
    }
    dp[0]=1;
    for (int i=1;i<(1<<n);i++){
        vector<int> arr;
        for (int j=0;j<n;j++){
            if (!(i&(1<<j))) continue;
            arr.pb(j);
        }
        // we loop through all independent subsets
        int sz=arr.size();
        for (int j=0;j<(1<<sz);j++){
            int curmask=0,num=0;
            for (int k=0;k<sz;k++){
                if (!(j&(1<<k))) continue;
                curmask^=(1<<arr[k]);
                num++;
            }
            if (!indep[curmask]) continue;
            if (num%2==1){
                dp[i]+=dp[i^curmask];
            }
            else {
                dp[i]-=dp[i^curmask];
            }
            dp[i]%=MOD;
        }
    }
    long long ans=dp[(1<<n)-1];
    ans*=m;
    ans%=MOD;
    ans*=power(2,MOD-2,MOD);
    ans%=MOD;
    cout<<ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // freopen("movie.in","r",stdin);
    // freopen("movie.out","w",stdout);
    //freopen("input1.in","r",stdin);
    // freopen("output1.out","w",stdout);
    //freopen("tower_rush_input.txt","r",stdin);
    //freopen("hackercup_output.txt","w",stdout);
    int tcs;
    // cin>>tcs;
    tcs=1;
    for (int i=1;i<=tcs;i++){
        // cout<<"Case #"<<i<<": ";
        runtc();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 0 ms 2908 KB Output is correct
3 Correct 0 ms 2908 KB Output is correct
4 Correct 0 ms 2908 KB Output is correct
5 Correct 0 ms 2908 KB Output is correct
6 Correct 0 ms 2908 KB Output is correct
7 Correct 1 ms 2696 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 0 ms 2908 KB Output is correct
3 Correct 0 ms 2908 KB Output is correct
4 Correct 0 ms 2908 KB Output is correct
5 Correct 0 ms 2908 KB Output is correct
6 Correct 0 ms 2908 KB Output is correct
7 Correct 1 ms 2696 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 2904 KB Output is correct
10 Correct 0 ms 2908 KB Output is correct
11 Correct 0 ms 2908 KB Output is correct
12 Correct 0 ms 2908 KB Output is correct
13 Correct 1 ms 2908 KB Output is correct
14 Correct 0 ms 2908 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 0 ms 2772 KB Output is correct
18 Correct 0 ms 2908 KB Output is correct
19 Correct 0 ms 2908 KB Output is correct
20 Correct 0 ms 2908 KB Output is correct
21 Correct 1 ms 2908 KB Output is correct
22 Correct 0 ms 2908 KB Output is correct
23 Correct 1 ms 2908 KB Output is correct
24 Correct 0 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 0 ms 2908 KB Output is correct
3 Correct 0 ms 2908 KB Output is correct
4 Correct 0 ms 2908 KB Output is correct
5 Correct 0 ms 2908 KB Output is correct
6 Correct 0 ms 2908 KB Output is correct
7 Correct 1 ms 2696 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 2904 KB Output is correct
10 Correct 0 ms 2908 KB Output is correct
11 Correct 0 ms 2908 KB Output is correct
12 Correct 0 ms 2908 KB Output is correct
13 Correct 1 ms 2908 KB Output is correct
14 Correct 0 ms 2908 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 0 ms 2772 KB Output is correct
18 Correct 0 ms 2908 KB Output is correct
19 Correct 0 ms 2908 KB Output is correct
20 Correct 0 ms 2908 KB Output is correct
21 Correct 1 ms 2908 KB Output is correct
22 Correct 0 ms 2908 KB Output is correct
23 Correct 1 ms 2908 KB Output is correct
24 Correct 0 ms 2908 KB Output is correct
25 Correct 1 ms 2908 KB Output is correct
26 Correct 0 ms 2908 KB Output is correct
27 Correct 0 ms 2908 KB Output is correct
28 Correct 0 ms 2908 KB Output is correct
29 Correct 0 ms 2908 KB Output is correct
30 Correct 1 ms 2904 KB Output is correct
31 Correct 1 ms 2908 KB Output is correct
32 Correct 1 ms 2908 KB Output is correct
33 Correct 1 ms 2908 KB Output is correct
34 Correct 1 ms 2908 KB Output is correct
35 Correct 0 ms 2908 KB Output is correct
36 Correct 1 ms 2908 KB Output is correct
37 Correct 1 ms 2908 KB Output is correct
38 Correct 0 ms 2908 KB Output is correct
39 Correct 1 ms 2908 KB Output is correct
40 Correct 1 ms 2908 KB Output is correct
41 Correct 1 ms 2908 KB Output is correct
42 Correct 1 ms 2908 KB Output is correct
43 Correct 1 ms 2908 KB Output is correct
44 Correct 1 ms 2908 KB Output is correct
45 Correct 1 ms 2908 KB Output is correct
46 Correct 1 ms 2904 KB Output is correct
47 Correct 1 ms 2908 KB Output is correct
48 Correct 1 ms 2908 KB Output is correct
49 Correct 1 ms 2908 KB Output is correct
50 Correct 1 ms 2908 KB Output is correct
51 Correct 1 ms 2908 KB Output is correct
52 Correct 1 ms 2908 KB Output is correct
53 Correct 2 ms 2904 KB Output is correct
54 Correct 1 ms 2908 KB Output is correct
55 Correct 1 ms 2908 KB Output is correct
56 Correct 1 ms 2908 KB Output is correct
57 Correct 1 ms 2908 KB Output is correct
58 Correct 1 ms 2728 KB Output is correct
59 Correct 1 ms 2908 KB Output is correct
60 Correct 1 ms 2908 KB Output is correct
61 Correct 2 ms 2908 KB Output is correct
62 Correct 1 ms 2696 KB Output is correct
63 Correct 1 ms 2908 KB Output is correct
64 Correct 1 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 0 ms 2908 KB Output is correct
3 Correct 0 ms 2908 KB Output is correct
4 Correct 0 ms 2908 KB Output is correct
5 Correct 0 ms 2908 KB Output is correct
6 Correct 0 ms 2908 KB Output is correct
7 Correct 1 ms 2696 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 2904 KB Output is correct
10 Correct 0 ms 2908 KB Output is correct
11 Correct 0 ms 2908 KB Output is correct
12 Correct 0 ms 2908 KB Output is correct
13 Correct 1 ms 2908 KB Output is correct
14 Correct 0 ms 2908 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 0 ms 2772 KB Output is correct
18 Correct 0 ms 2908 KB Output is correct
19 Correct 0 ms 2908 KB Output is correct
20 Correct 0 ms 2908 KB Output is correct
21 Correct 1 ms 2908 KB Output is correct
22 Correct 0 ms 2908 KB Output is correct
23 Correct 1 ms 2908 KB Output is correct
24 Correct 0 ms 2908 KB Output is correct
25 Correct 1 ms 2908 KB Output is correct
26 Correct 0 ms 2908 KB Output is correct
27 Correct 0 ms 2908 KB Output is correct
28 Correct 0 ms 2908 KB Output is correct
29 Correct 0 ms 2908 KB Output is correct
30 Correct 1 ms 2904 KB Output is correct
31 Correct 1 ms 2908 KB Output is correct
32 Correct 1 ms 2908 KB Output is correct
33 Correct 1 ms 2908 KB Output is correct
34 Correct 1 ms 2908 KB Output is correct
35 Correct 0 ms 2908 KB Output is correct
36 Correct 1 ms 2908 KB Output is correct
37 Correct 1 ms 2908 KB Output is correct
38 Correct 0 ms 2908 KB Output is correct
39 Correct 1 ms 2908 KB Output is correct
40 Correct 1 ms 2908 KB Output is correct
41 Correct 1 ms 2908 KB Output is correct
42 Correct 1 ms 2908 KB Output is correct
43 Correct 1 ms 2908 KB Output is correct
44 Correct 1 ms 2908 KB Output is correct
45 Correct 1 ms 2908 KB Output is correct
46 Correct 1 ms 2904 KB Output is correct
47 Correct 1 ms 2908 KB Output is correct
48 Correct 1 ms 2908 KB Output is correct
49 Correct 1 ms 2908 KB Output is correct
50 Correct 1 ms 2908 KB Output is correct
51 Correct 1 ms 2908 KB Output is correct
52 Correct 1 ms 2908 KB Output is correct
53 Correct 2 ms 2904 KB Output is correct
54 Correct 1 ms 2908 KB Output is correct
55 Correct 1 ms 2908 KB Output is correct
56 Correct 1 ms 2908 KB Output is correct
57 Correct 1 ms 2908 KB Output is correct
58 Correct 1 ms 2728 KB Output is correct
59 Correct 1 ms 2908 KB Output is correct
60 Correct 1 ms 2908 KB Output is correct
61 Correct 2 ms 2908 KB Output is correct
62 Correct 1 ms 2696 KB Output is correct
63 Correct 1 ms 2908 KB Output is correct
64 Correct 1 ms 2908 KB Output is correct
65 Correct 83 ms 2908 KB Output is correct
66 Correct 81 ms 2908 KB Output is correct
67 Correct 80 ms 2984 KB Output is correct
68 Correct 78 ms 2904 KB Output is correct
69 Correct 112 ms 3204 KB Output is correct
70 Correct 103 ms 2904 KB Output is correct
71 Correct 98 ms 2904 KB Output is correct
72 Correct 80 ms 3024 KB Output is correct
73 Correct 92 ms 2904 KB Output is correct
74 Correct 92 ms 3036 KB Output is correct
75 Correct 88 ms 3016 KB Output is correct
76 Correct 83 ms 2904 KB Output is correct
77 Correct 304 ms 3408 KB Output is correct
78 Correct 307 ms 3020 KB Output is correct
79 Correct 285 ms 3152 KB Output is correct
80 Correct 287 ms 3156 KB Output is correct
81 Incorrect 309 ms 3156 KB Output isn't correct
82 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 0 ms 2908 KB Output is correct
3 Correct 0 ms 2908 KB Output is correct
4 Correct 0 ms 2908 KB Output is correct
5 Correct 0 ms 2908 KB Output is correct
6 Correct 0 ms 2908 KB Output is correct
7 Correct 1 ms 2696 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 2904 KB Output is correct
10 Correct 0 ms 2908 KB Output is correct
11 Correct 0 ms 2908 KB Output is correct
12 Correct 0 ms 2908 KB Output is correct
13 Correct 1 ms 2908 KB Output is correct
14 Correct 0 ms 2908 KB Output is correct
15 Correct 1 ms 2908 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 0 ms 2772 KB Output is correct
18 Correct 0 ms 2908 KB Output is correct
19 Correct 0 ms 2908 KB Output is correct
20 Correct 0 ms 2908 KB Output is correct
21 Correct 1 ms 2908 KB Output is correct
22 Correct 0 ms 2908 KB Output is correct
23 Correct 1 ms 2908 KB Output is correct
24 Correct 0 ms 2908 KB Output is correct
25 Correct 1 ms 2908 KB Output is correct
26 Correct 0 ms 2908 KB Output is correct
27 Correct 0 ms 2908 KB Output is correct
28 Correct 0 ms 2908 KB Output is correct
29 Correct 0 ms 2908 KB Output is correct
30 Correct 1 ms 2904 KB Output is correct
31 Correct 1 ms 2908 KB Output is correct
32 Correct 1 ms 2908 KB Output is correct
33 Correct 1 ms 2908 KB Output is correct
34 Correct 1 ms 2908 KB Output is correct
35 Correct 0 ms 2908 KB Output is correct
36 Correct 1 ms 2908 KB Output is correct
37 Correct 1 ms 2908 KB Output is correct
38 Correct 0 ms 2908 KB Output is correct
39 Correct 1 ms 2908 KB Output is correct
40 Correct 1 ms 2908 KB Output is correct
41 Correct 1 ms 2908 KB Output is correct
42 Correct 1 ms 2908 KB Output is correct
43 Correct 1 ms 2908 KB Output is correct
44 Correct 1 ms 2908 KB Output is correct
45 Correct 1 ms 2908 KB Output is correct
46 Correct 1 ms 2904 KB Output is correct
47 Correct 1 ms 2908 KB Output is correct
48 Correct 1 ms 2908 KB Output is correct
49 Correct 1 ms 2908 KB Output is correct
50 Correct 1 ms 2908 KB Output is correct
51 Correct 1 ms 2908 KB Output is correct
52 Correct 1 ms 2908 KB Output is correct
53 Correct 2 ms 2904 KB Output is correct
54 Correct 1 ms 2908 KB Output is correct
55 Correct 1 ms 2908 KB Output is correct
56 Correct 1 ms 2908 KB Output is correct
57 Correct 1 ms 2908 KB Output is correct
58 Correct 1 ms 2728 KB Output is correct
59 Correct 1 ms 2908 KB Output is correct
60 Correct 1 ms 2908 KB Output is correct
61 Correct 2 ms 2908 KB Output is correct
62 Correct 1 ms 2696 KB Output is correct
63 Correct 1 ms 2908 KB Output is correct
64 Correct 1 ms 2908 KB Output is correct
65 Correct 83 ms 2908 KB Output is correct
66 Correct 81 ms 2908 KB Output is correct
67 Correct 80 ms 2984 KB Output is correct
68 Correct 78 ms 2904 KB Output is correct
69 Correct 112 ms 3204 KB Output is correct
70 Correct 103 ms 2904 KB Output is correct
71 Correct 98 ms 2904 KB Output is correct
72 Correct 80 ms 3024 KB Output is correct
73 Correct 92 ms 2904 KB Output is correct
74 Correct 92 ms 3036 KB Output is correct
75 Correct 88 ms 3016 KB Output is correct
76 Correct 83 ms 2904 KB Output is correct
77 Correct 304 ms 3408 KB Output is correct
78 Correct 307 ms 3020 KB Output is correct
79 Correct 285 ms 3152 KB Output is correct
80 Correct 287 ms 3156 KB Output is correct
81 Incorrect 309 ms 3156 KB Output isn't correct
82 Halted 0 ms 0 KB -