답안 #928414

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
928414 2024-02-16T10:49:40 Z vjudge1 Amusement Park (CEOI19_amusementpark) C++17
100 / 100
1299 ms 11172 KB
#include<bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define ll long long
#define maksim gay
#define int ll
#define pb push_back
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define mem(a,i) memset(a,i,sizeof(a))
#define in insert
#define lb lower_bound
#define ub upper_bound

const int MAX=400;
const int inf=1e10;
const int N=2e5;
const int mod=998244353;

int binpow(int a,int n){
  if(n==0)return 1;
  if(n%2)return a*binpow(a,n-1)%mod;
  int k=binpow(a,n/2);
  return k*k%mod;
}

int n,m;
int d[20][20];
int a[MAX],b[MAX];
int dp[(1<<20)];
int f[(1<<20)];
int cnt[(1<<20)];

int bit(int i,int j){
  return (i>>j)&1;
}

void add(int &x,int y){
  x+=y;
  if(x>=mod)x-=mod;
  if(x<0)x+=mod;
}

void solve(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>a[i]>>b[i];
    d[a[i]-1][b[i]-1]=d[b[i]-1][a[i]-1]=1;
  }
  for(int i=0;i<(1<<n);i++){
    f[i]=1;
    for(int j=0;j<n;j++){
      if(bit(i,j))cnt[i]++;
      for(int k=j+1;k<n;k++){
        // cout<<i<<" "<<j<<" "<<k<<" "<<d[j][k]<<"\n";
        if(bit(i,j)&&bit(i,k)&&d[j][k]){
          f[i]=0;
        }
      }
    }
    // cout<<i<<" "<<f[i]<<"\n";
  }
  dp[0]=1;
  for(int i=1;i<(1<<n);i++){
    for(int j=i;j;j=(j-1)&i){
      if(f[j]){
        // cout<<i<<" "<<j<<"\n";
        if(cnt[j]%2==1){
          add(dp[i],dp[j^i]);
        }
        else add(dp[i],-dp[j^i]);
      }
    }
    // cout<<i<<" "<<dp[i]<<"\n";
  }
  // cout<<dp[(1<<n)-1]<<"\n";
  cout<<dp[(1<<n)-1]*m%mod*binpow(2,mod-2)%mod<<"\n";
}


main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t=1;
  // cin>>t;
  while(t--){
    solve();
  }
}

Compilation message

amusementpark.cpp:85:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   85 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4440 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 1 ms 4440 KB Output is correct
30 Correct 1 ms 4440 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 4576 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
55 Correct 1 ms 4440 KB Output is correct
56 Correct 1 ms 4440 KB Output is correct
57 Correct 1 ms 4444 KB Output is correct
58 Correct 1 ms 4444 KB Output is correct
59 Correct 1 ms 4444 KB Output is correct
60 Correct 1 ms 4440 KB Output is correct
61 Correct 1 ms 4444 KB Output is correct
62 Correct 1 ms 4444 KB Output is correct
63 Correct 1 ms 4444 KB Output is correct
64 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4440 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 1 ms 4440 KB Output is correct
30 Correct 1 ms 4440 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 4576 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
55 Correct 1 ms 4440 KB Output is correct
56 Correct 1 ms 4440 KB Output is correct
57 Correct 1 ms 4444 KB Output is correct
58 Correct 1 ms 4444 KB Output is correct
59 Correct 1 ms 4444 KB Output is correct
60 Correct 1 ms 4440 KB Output is correct
61 Correct 1 ms 4444 KB Output is correct
62 Correct 1 ms 4444 KB Output is correct
63 Correct 1 ms 4444 KB Output is correct
64 Correct 1 ms 4444 KB Output is correct
65 Correct 12 ms 4700 KB Output is correct
66 Correct 12 ms 4700 KB Output is correct
67 Correct 11 ms 4700 KB Output is correct
68 Correct 10 ms 4700 KB Output is correct
69 Correct 12 ms 4668 KB Output is correct
70 Correct 11 ms 4700 KB Output is correct
71 Correct 11 ms 4700 KB Output is correct
72 Correct 11 ms 4700 KB Output is correct
73 Correct 10 ms 4700 KB Output is correct
74 Correct 11 ms 4516 KB Output is correct
75 Correct 10 ms 4616 KB Output is correct
76 Correct 9 ms 4700 KB Output is correct
77 Correct 36 ms 8796 KB Output is correct
78 Correct 35 ms 8796 KB Output is correct
79 Correct 34 ms 8860 KB Output is correct
80 Correct 27 ms 8796 KB Output is correct
81 Correct 26 ms 8796 KB Output is correct
82 Correct 24 ms 8796 KB Output is correct
83 Correct 23 ms 8796 KB Output is correct
84 Correct 23 ms 8860 KB Output is correct
85 Correct 34 ms 8796 KB Output is correct
86 Correct 32 ms 8792 KB Output is correct
87 Correct 32 ms 8864 KB Output is correct
88 Correct 33 ms 8852 KB Output is correct
89 Correct 28 ms 8796 KB Output is correct
90 Correct 28 ms 8864 KB Output is correct
91 Correct 29 ms 8800 KB Output is correct
92 Correct 27 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4440 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 1 ms 4440 KB Output is correct
30 Correct 1 ms 4440 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 4576 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
55 Correct 1 ms 4440 KB Output is correct
56 Correct 1 ms 4440 KB Output is correct
57 Correct 1 ms 4444 KB Output is correct
58 Correct 1 ms 4444 KB Output is correct
59 Correct 1 ms 4444 KB Output is correct
60 Correct 1 ms 4440 KB Output is correct
61 Correct 1 ms 4444 KB Output is correct
62 Correct 1 ms 4444 KB Output is correct
63 Correct 1 ms 4444 KB Output is correct
64 Correct 1 ms 4444 KB Output is correct
65 Correct 12 ms 4700 KB Output is correct
66 Correct 12 ms 4700 KB Output is correct
67 Correct 11 ms 4700 KB Output is correct
68 Correct 10 ms 4700 KB Output is correct
69 Correct 12 ms 4668 KB Output is correct
70 Correct 11 ms 4700 KB Output is correct
71 Correct 11 ms 4700 KB Output is correct
72 Correct 11 ms 4700 KB Output is correct
73 Correct 10 ms 4700 KB Output is correct
74 Correct 11 ms 4516 KB Output is correct
75 Correct 10 ms 4616 KB Output is correct
76 Correct 9 ms 4700 KB Output is correct
77 Correct 36 ms 8796 KB Output is correct
78 Correct 35 ms 8796 KB Output is correct
79 Correct 34 ms 8860 KB Output is correct
80 Correct 27 ms 8796 KB Output is correct
81 Correct 26 ms 8796 KB Output is correct
82 Correct 24 ms 8796 KB Output is correct
83 Correct 23 ms 8796 KB Output is correct
84 Correct 23 ms 8860 KB Output is correct
85 Correct 34 ms 8796 KB Output is correct
86 Correct 32 ms 8792 KB Output is correct
87 Correct 32 ms 8864 KB Output is correct
88 Correct 33 ms 8852 KB Output is correct
89 Correct 28 ms 8796 KB Output is correct
90 Correct 28 ms 8864 KB Output is correct
91 Correct 29 ms 8800 KB Output is correct
92 Correct 27 ms 8796 KB Output is correct
93 Correct 749 ms 10576 KB Output is correct
94 Correct 746 ms 10716 KB Output is correct
95 Correct 775 ms 10916 KB Output is correct
96 Correct 679 ms 10536 KB Output is correct
97 Correct 644 ms 10884 KB Output is correct
98 Correct 739 ms 11172 KB Output is correct
99 Correct 101 ms 9044 KB Output is correct
100 Correct 85 ms 9040 KB Output is correct
101 Correct 79 ms 9008 KB Output is correct
102 Correct 72 ms 9044 KB Output is correct
103 Correct 455 ms 9612 KB Output is correct
104 Correct 288 ms 9552 KB Output is correct
105 Correct 255 ms 9680 KB Output is correct
106 Correct 226 ms 9548 KB Output is correct
107 Correct 1299 ms 10604 KB Output is correct
108 Correct 708 ms 11088 KB Output is correct
109 Correct 670 ms 10708 KB Output is correct
110 Correct 552 ms 10580 KB Output is correct
111 Correct 66 ms 9040 KB Output is correct
112 Correct 61 ms 9108 KB Output is correct
113 Correct 59 ms 9176 KB Output is correct
114 Correct 126 ms 9044 KB Output is correct
115 Correct 93 ms 9112 KB Output is correct
116 Correct 89 ms 9044 KB Output is correct
117 Correct 75 ms 9044 KB Output is correct
118 Correct 79 ms 9108 KB Output is correct
119 Correct 83 ms 9156 KB Output is correct
120 Correct 69 ms 9040 KB Output is correct
121 Correct 64 ms 9044 KB Output is correct
122 Correct 223 ms 9748 KB Output is correct
123 Correct 180 ms 9544 KB Output is correct
124 Correct 165 ms 9608 KB Output is correct
125 Correct 165 ms 9860 KB Output is correct
126 Correct 153 ms 9580 KB Output is correct
127 Correct 143 ms 9564 KB Output is correct
128 Correct 137 ms 9620 KB Output is correct
129 Correct 140 ms 9556 KB Output is correct
130 Correct 123 ms 9552 KB Output is correct
131 Correct 329 ms 9588 KB Output is correct
132 Correct 265 ms 9556 KB Output is correct
133 Correct 233 ms 9556 KB Output is correct
134 Correct 263 ms 9592 KB Output is correct
135 Correct 249 ms 9552 KB Output is correct
136 Correct 254 ms 9688 KB Output is correct
137 Correct 208 ms 9800 KB Output is correct
138 Correct 181 ms 9624 KB Output is correct
139 Correct 208 ms 9856 KB Output is correct
140 Correct 225 ms 9572 KB Output is correct
141 Correct 187 ms 9600 KB Output is correct
142 Correct 477 ms 10828 KB Output is correct
143 Correct 435 ms 10580 KB Output is correct
144 Correct 412 ms 10700 KB Output is correct
145 Correct 411 ms 10632 KB Output is correct
146 Correct 386 ms 10688 KB Output is correct
147 Correct 343 ms 10696 KB Output is correct
148 Correct 486 ms 10576 KB Output is correct
149 Correct 474 ms 10832 KB Output is correct
150 Correct 471 ms 10580 KB Output is correct
151 Correct 547 ms 10616 KB Output is correct
152 Correct 527 ms 11140 KB Output is correct
153 Correct 671 ms 10712 KB Output is correct
154 Correct 669 ms 10628 KB Output is correct
155 Correct 621 ms 10836 KB Output is correct
156 Correct 588 ms 10556 KB Output is correct
157 Correct 682 ms 10832 KB Output is correct
158 Correct 590 ms 10580 KB Output is correct
159 Correct 594 ms 10884 KB Output is correct
160 Correct 589 ms 10784 KB Output is correct
161 Correct 532 ms 10580 KB Output is correct
162 Correct 518 ms 10836 KB Output is correct
163 Correct 504 ms 10848 KB Output is correct
164 Correct 501 ms 10692 KB Output is correct
165 Correct 493 ms 10920 KB Output is correct
166 Correct 454 ms 10756 KB Output is correct
167 Correct 488 ms 10696 KB Output is correct