Submission #1052455

# Submission time Handle Problem Language Result Execution time Memory
1052455 2024-08-10T14:42:10 Z handlename Amusement Park (CEOI19_amusementpark) C++17
63 / 100
3000 ms 3788 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%MOD+MOD)%MOD;
}
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 2904 KB Output is correct
2 Correct 0 ms 2908 KB Output is correct
3 Correct 0 ms 2908 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 0 ms 2908 KB Output is correct
7 Correct 0 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 0 ms 2908 KB Output is correct
3 Correct 0 ms 2908 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 0 ms 2908 KB Output is correct
7 Correct 0 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 0 ms 2908 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 2904 KB Output is correct
13 Correct 1 ms 2904 KB Output is correct
14 Correct 1 ms 2908 KB Output is correct
15 Correct 0 ms 2904 KB Output is correct
16 Correct 0 ms 2908 KB Output is correct
17 Correct 0 ms 2908 KB Output is correct
18 Correct 1 ms 2908 KB Output is correct
19 Correct 1 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 0 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 2904 KB Output is correct
2 Correct 0 ms 2908 KB Output is correct
3 Correct 0 ms 2908 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 0 ms 2908 KB Output is correct
7 Correct 0 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 0 ms 2908 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 2904 KB Output is correct
13 Correct 1 ms 2904 KB Output is correct
14 Correct 1 ms 2908 KB Output is correct
15 Correct 0 ms 2904 KB Output is correct
16 Correct 0 ms 2908 KB Output is correct
17 Correct 0 ms 2908 KB Output is correct
18 Correct 1 ms 2908 KB Output is correct
19 Correct 1 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 0 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 1 ms 2908 KB Output is correct
27 Correct 0 ms 2904 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 2908 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 1 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 1 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 2908 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 2904 KB Output is correct
52 Correct 1 ms 2908 KB Output is correct
53 Correct 1 ms 2908 KB Output is correct
54 Correct 1 ms 2908 KB Output is correct
55 Correct 2 ms 2908 KB Output is correct
56 Correct 1 ms 2908 KB Output is correct
57 Correct 2 ms 2908 KB Output is correct
58 Correct 1 ms 2908 KB Output is correct
59 Correct 1 ms 2908 KB Output is correct
60 Correct 2 ms 2908 KB Output is correct
61 Correct 2 ms 2908 KB Output is correct
62 Correct 1 ms 2908 KB Output is correct
63 Correct 2 ms 2908 KB Output is correct
64 Correct 2 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 0 ms 2908 KB Output is correct
3 Correct 0 ms 2908 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 0 ms 2908 KB Output is correct
7 Correct 0 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 0 ms 2908 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 2904 KB Output is correct
13 Correct 1 ms 2904 KB Output is correct
14 Correct 1 ms 2908 KB Output is correct
15 Correct 0 ms 2904 KB Output is correct
16 Correct 0 ms 2908 KB Output is correct
17 Correct 0 ms 2908 KB Output is correct
18 Correct 1 ms 2908 KB Output is correct
19 Correct 1 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 0 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 1 ms 2908 KB Output is correct
27 Correct 0 ms 2904 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 2908 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 1 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 1 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 2908 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 2904 KB Output is correct
52 Correct 1 ms 2908 KB Output is correct
53 Correct 1 ms 2908 KB Output is correct
54 Correct 1 ms 2908 KB Output is correct
55 Correct 2 ms 2908 KB Output is correct
56 Correct 1 ms 2908 KB Output is correct
57 Correct 2 ms 2908 KB Output is correct
58 Correct 1 ms 2908 KB Output is correct
59 Correct 1 ms 2908 KB Output is correct
60 Correct 2 ms 2908 KB Output is correct
61 Correct 2 ms 2908 KB Output is correct
62 Correct 1 ms 2908 KB Output is correct
63 Correct 2 ms 2908 KB Output is correct
64 Correct 2 ms 2908 KB Output is correct
65 Correct 110 ms 2924 KB Output is correct
66 Correct 80 ms 2904 KB Output is correct
67 Correct 94 ms 2996 KB Output is correct
68 Correct 77 ms 2908 KB Output is correct
69 Correct 115 ms 3024 KB Output is correct
70 Correct 101 ms 2908 KB Output is correct
71 Correct 106 ms 2904 KB Output is correct
72 Correct 81 ms 2904 KB Output is correct
73 Correct 101 ms 3284 KB Output is correct
74 Correct 94 ms 2996 KB Output is correct
75 Correct 88 ms 2980 KB Output is correct
76 Correct 78 ms 2908 KB Output is correct
77 Correct 308 ms 3156 KB Output is correct
78 Correct 295 ms 3152 KB Output is correct
79 Correct 305 ms 2976 KB Output is correct
80 Correct 287 ms 3156 KB Output is correct
81 Correct 323 ms 2928 KB Output is correct
82 Correct 294 ms 3152 KB Output is correct
83 Correct 274 ms 2952 KB Output is correct
84 Correct 276 ms 3152 KB Output is correct
85 Correct 385 ms 2980 KB Output is correct
86 Correct 358 ms 3152 KB Output is correct
87 Correct 354 ms 3156 KB Output is correct
88 Correct 303 ms 3144 KB Output is correct
89 Correct 322 ms 3000 KB Output is correct
90 Correct 352 ms 3236 KB Output is correct
91 Correct 320 ms 3008 KB Output is correct
92 Correct 284 ms 3024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2904 KB Output is correct
2 Correct 0 ms 2908 KB Output is correct
3 Correct 0 ms 2908 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 0 ms 2908 KB Output is correct
7 Correct 0 ms 2908 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 0 ms 2908 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 2904 KB Output is correct
13 Correct 1 ms 2904 KB Output is correct
14 Correct 1 ms 2908 KB Output is correct
15 Correct 0 ms 2904 KB Output is correct
16 Correct 0 ms 2908 KB Output is correct
17 Correct 0 ms 2908 KB Output is correct
18 Correct 1 ms 2908 KB Output is correct
19 Correct 1 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 0 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 1 ms 2908 KB Output is correct
27 Correct 0 ms 2904 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 2908 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 1 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 1 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 2908 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 2904 KB Output is correct
52 Correct 1 ms 2908 KB Output is correct
53 Correct 1 ms 2908 KB Output is correct
54 Correct 1 ms 2908 KB Output is correct
55 Correct 2 ms 2908 KB Output is correct
56 Correct 1 ms 2908 KB Output is correct
57 Correct 2 ms 2908 KB Output is correct
58 Correct 1 ms 2908 KB Output is correct
59 Correct 1 ms 2908 KB Output is correct
60 Correct 2 ms 2908 KB Output is correct
61 Correct 2 ms 2908 KB Output is correct
62 Correct 1 ms 2908 KB Output is correct
63 Correct 2 ms 2908 KB Output is correct
64 Correct 2 ms 2908 KB Output is correct
65 Correct 110 ms 2924 KB Output is correct
66 Correct 80 ms 2904 KB Output is correct
67 Correct 94 ms 2996 KB Output is correct
68 Correct 77 ms 2908 KB Output is correct
69 Correct 115 ms 3024 KB Output is correct
70 Correct 101 ms 2908 KB Output is correct
71 Correct 106 ms 2904 KB Output is correct
72 Correct 81 ms 2904 KB Output is correct
73 Correct 101 ms 3284 KB Output is correct
74 Correct 94 ms 2996 KB Output is correct
75 Correct 88 ms 2980 KB Output is correct
76 Correct 78 ms 2908 KB Output is correct
77 Correct 308 ms 3156 KB Output is correct
78 Correct 295 ms 3152 KB Output is correct
79 Correct 305 ms 2976 KB Output is correct
80 Correct 287 ms 3156 KB Output is correct
81 Correct 323 ms 2928 KB Output is correct
82 Correct 294 ms 3152 KB Output is correct
83 Correct 274 ms 2952 KB Output is correct
84 Correct 276 ms 3152 KB Output is correct
85 Correct 385 ms 2980 KB Output is correct
86 Correct 358 ms 3152 KB Output is correct
87 Correct 354 ms 3156 KB Output is correct
88 Correct 303 ms 3144 KB Output is correct
89 Correct 322 ms 3000 KB Output is correct
90 Correct 352 ms 3236 KB Output is correct
91 Correct 320 ms 3008 KB Output is correct
92 Correct 284 ms 3024 KB Output is correct
93 Execution timed out 3062 ms 3788 KB Time limit exceeded
94 Halted 0 ms 0 KB -