Submission #467900

# Submission time Handle Problem Language Result Execution time Memory
467900 2021-08-25T13:56:37 Z ivan_tudor Amusement Park (CEOI19_amusementpark) C++14
100 / 100
2879 ms 1820 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 18;
bool canb[1<<N];
int dp[1<<N];
vector<int> gr[N];
const int MOD =998244353;
void add(int &x, long long y){
  y%=MOD;
  x+=y;
  if(x >= MOD)
    x-=MOD;
  if(x < 0)
    x+=MOD;
}
int main()
{
  //freopen(".in","r",stdin);
  ios::sync_with_stdio(false);
  cin.tie(0),cout.tie(0);
  int n, m;
  cin>>n>>m;
  for(int i = 1; i <= m; i++){
    int x, y;
    cin>>x>>y;
    x--;
    y--;
    gr[x].push_back(y);
    gr[y].push_back(x);
  }
  canb[0] = true;
  for(int mask = 0; mask < (1<<n); mask++){
    if(canb[mask] == false)
      continue;

    for(int i = 0; i < n; i++){
      bool ok = true;
      if((mask & (1<<i)) == 0){
        for(auto x:gr[i]){
          if(mask & (1<<x)){
            ok = false;
            break;
          }
        }
        canb[mask ^(1<<i)] = ok;
      }
    }
  }
  dp[0] = 1;
  for(int mask = 0; mask < (1<<n); mask ++){
    for(int layer = mask; layer > 0; layer = (layer - 1) & mask){
      if(canb[layer]){
        if(__builtin_popcount(layer)%2 == 1)
          add(dp[mask], dp[mask ^ layer]);
        else
          add(dp[mask], -dp[mask ^ layer]);
      }
    }
  }
  cout<<(1LL * dp[(1<<n) - 1] *((MOD + 1) / 2) % MOD * m) % MOD;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 320 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 1 ms 404 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 1 ms 204 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 1 ms 204 KB Output is correct
54 Correct 1 ms 204 KB Output is correct
55 Correct 1 ms 204 KB Output is correct
56 Correct 1 ms 320 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 320 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 1 ms 332 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 320 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 1 ms 404 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 1 ms 204 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 1 ms 204 KB Output is correct
54 Correct 1 ms 204 KB Output is correct
55 Correct 1 ms 204 KB Output is correct
56 Correct 1 ms 320 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 320 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 1 ms 332 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
65 Correct 15 ms 400 KB Output is correct
66 Correct 11 ms 400 KB Output is correct
67 Correct 10 ms 320 KB Output is correct
68 Correct 9 ms 384 KB Output is correct
69 Correct 28 ms 356 KB Output is correct
70 Correct 20 ms 384 KB Output is correct
71 Correct 20 ms 372 KB Output is correct
72 Correct 19 ms 320 KB Output is correct
73 Correct 16 ms 316 KB Output is correct
74 Correct 16 ms 312 KB Output is correct
75 Correct 15 ms 392 KB Output is correct
76 Correct 15 ms 364 KB Output is correct
77 Correct 42 ms 428 KB Output is correct
78 Correct 35 ms 456 KB Output is correct
79 Correct 33 ms 440 KB Output is correct
80 Correct 28 ms 416 KB Output is correct
81 Correct 26 ms 460 KB Output is correct
82 Correct 25 ms 448 KB Output is correct
83 Correct 22 ms 452 KB Output is correct
84 Correct 22 ms 460 KB Output is correct
85 Correct 78 ms 384 KB Output is correct
86 Correct 61 ms 452 KB Output is correct
87 Correct 59 ms 400 KB Output is correct
88 Correct 57 ms 392 KB Output is correct
89 Correct 48 ms 468 KB Output is correct
90 Correct 44 ms 452 KB Output is correct
91 Correct 44 ms 372 KB Output is correct
92 Correct 42 ms 444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 320 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 1 ms 404 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 1 ms 204 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 1 ms 204 KB Output is correct
54 Correct 1 ms 204 KB Output is correct
55 Correct 1 ms 204 KB Output is correct
56 Correct 1 ms 320 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 320 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 1 ms 332 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
65 Correct 15 ms 400 KB Output is correct
66 Correct 11 ms 400 KB Output is correct
67 Correct 10 ms 320 KB Output is correct
68 Correct 9 ms 384 KB Output is correct
69 Correct 28 ms 356 KB Output is correct
70 Correct 20 ms 384 KB Output is correct
71 Correct 20 ms 372 KB Output is correct
72 Correct 19 ms 320 KB Output is correct
73 Correct 16 ms 316 KB Output is correct
74 Correct 16 ms 312 KB Output is correct
75 Correct 15 ms 392 KB Output is correct
76 Correct 15 ms 364 KB Output is correct
77 Correct 42 ms 428 KB Output is correct
78 Correct 35 ms 456 KB Output is correct
79 Correct 33 ms 440 KB Output is correct
80 Correct 28 ms 416 KB Output is correct
81 Correct 26 ms 460 KB Output is correct
82 Correct 25 ms 448 KB Output is correct
83 Correct 22 ms 452 KB Output is correct
84 Correct 22 ms 460 KB Output is correct
85 Correct 78 ms 384 KB Output is correct
86 Correct 61 ms 452 KB Output is correct
87 Correct 59 ms 400 KB Output is correct
88 Correct 57 ms 392 KB Output is correct
89 Correct 48 ms 468 KB Output is correct
90 Correct 44 ms 452 KB Output is correct
91 Correct 44 ms 372 KB Output is correct
92 Correct 42 ms 444 KB Output is correct
93 Correct 1610 ms 1564 KB Output is correct
94 Correct 1626 ms 1804 KB Output is correct
95 Correct 1651 ms 1684 KB Output is correct
96 Correct 1276 ms 1628 KB Output is correct
97 Correct 1108 ms 1544 KB Output is correct
98 Correct 1270 ms 1772 KB Output is correct
99 Correct 134 ms 580 KB Output is correct
100 Correct 108 ms 576 KB Output is correct
101 Correct 94 ms 580 KB Output is correct
102 Correct 79 ms 580 KB Output is correct
103 Correct 944 ms 1196 KB Output is correct
104 Correct 525 ms 932 KB Output is correct
105 Correct 404 ms 1008 KB Output is correct
106 Correct 300 ms 880 KB Output is correct
107 Correct 2879 ms 1820 KB Output is correct
108 Correct 1140 ms 1604 KB Output is correct
109 Correct 836 ms 1604 KB Output is correct
110 Correct 666 ms 1540 KB Output is correct
111 Correct 71 ms 568 KB Output is correct
112 Correct 63 ms 580 KB Output is correct
113 Correct 57 ms 520 KB Output is correct
114 Correct 235 ms 592 KB Output is correct
115 Correct 178 ms 608 KB Output is correct
116 Correct 177 ms 584 KB Output is correct
117 Correct 183 ms 544 KB Output is correct
118 Correct 144 ms 512 KB Output is correct
119 Correct 135 ms 568 KB Output is correct
120 Correct 133 ms 560 KB Output is correct
121 Correct 129 ms 612 KB Output is correct
122 Correct 260 ms 924 KB Output is correct
123 Correct 223 ms 1012 KB Output is correct
124 Correct 183 ms 840 KB Output is correct
125 Correct 169 ms 836 KB Output is correct
126 Correct 162 ms 964 KB Output is correct
127 Correct 145 ms 932 KB Output is correct
128 Correct 133 ms 852 KB Output is correct
129 Correct 125 ms 820 KB Output is correct
130 Correct 119 ms 872 KB Output is correct
131 Correct 696 ms 940 KB Output is correct
132 Correct 542 ms 1052 KB Output is correct
133 Correct 505 ms 968 KB Output is correct
134 Correct 503 ms 836 KB Output is correct
135 Correct 419 ms 1112 KB Output is correct
136 Correct 401 ms 948 KB Output is correct
137 Correct 381 ms 984 KB Output is correct
138 Correct 380 ms 828 KB Output is correct
139 Correct 336 ms 1120 KB Output is correct
140 Correct 327 ms 916 KB Output is correct
141 Correct 290 ms 840 KB Output is correct
142 Correct 523 ms 1604 KB Output is correct
143 Correct 479 ms 1476 KB Output is correct
144 Correct 434 ms 1372 KB Output is correct
145 Correct 396 ms 1476 KB Output is correct
146 Correct 374 ms 1392 KB Output is correct
147 Correct 345 ms 1488 KB Output is correct
148 Correct 561 ms 1536 KB Output is correct
149 Correct 539 ms 1436 KB Output is correct
150 Correct 517 ms 1512 KB Output is correct
151 Correct 779 ms 1472 KB Output is correct
152 Correct 758 ms 1456 KB Output is correct
153 Correct 1291 ms 1672 KB Output is correct
154 Correct 1238 ms 1588 KB Output is correct
155 Correct 1175 ms 1592 KB Output is correct
156 Correct 1132 ms 1560 KB Output is correct
157 Correct 1175 ms 1640 KB Output is correct
158 Correct 1147 ms 1508 KB Output is correct
159 Correct 1004 ms 1604 KB Output is correct
160 Correct 894 ms 1516 KB Output is correct
161 Correct 866 ms 1544 KB Output is correct
162 Correct 818 ms 1604 KB Output is correct
163 Correct 801 ms 1576 KB Output is correct
164 Correct 760 ms 1600 KB Output is correct
165 Correct 698 ms 1556 KB Output is correct
166 Correct 690 ms 1556 KB Output is correct
167 Correct 681 ms 1316 KB Output is correct