Submission #1055663

# Submission time Handle Problem Language Result Execution time Memory
1055663 2024-08-13T02:44:08 Z coolsentenceidontremember Amusement Park (CEOI19_amusementpark) C++17
100 / 100
1309 ms 2904 KB
#include<bits/stdc++.h>

#pragma GCC optimize("O3", "unroll-loops")


#define ll long long
#define ld long double
#define ff first
#define ss second
#define db double
#define time_begin() auto begin = chrono::high_resolution_clock::now()
#define time_end() auto end = chrono::high_resolution_clock::now(); auto elapsed = chrono::duration_cast<chrono::nanoseconds>(end-begin); auto sec = elapsed.count() * 1e-9; cerr << "\n\nExecution time: " << sec << " seconds";
#define check_time() cerr << "\nStatus : "; if (sec>1) cerr << "Time Limit Exceeded 1!!!1!111"; else cerr << "You good brother"
#define precision(x) fixed << setprecision((x))
#define check_ok() cout << "it aight" << '\n'
using namespace std;



void setIO(string s = ""){
 ios_base::sync_with_stdio(false);
 cin.tie(nullptr);
 cout.tie(nullptr);
 if (!s.empty()){
	freopen((s+".in").c_str(), "r", stdin);
	freopen((s+".out").c_str(), "w", stdout);
	}
}

const int N = 18;
const ll mod = 998244353;
const ll two_inv = 499122177;
bool ind[1<<N];
int adj[N];
ll dp[1<<N];




int main(){
  int n, m;
  cin >> n >> m;
  memset(adj, 0, sizeof adj);
  fill(ind, ind + (1<<n), 1);
  for (int i = 1; i <= m; i++){
  	int u, v;
  	cin >> u >> v;
  	u--; v--;
  	adj[u] |= (1<<v);
  	ind[(1<<u)|(1<<v)] = 0;
  }
  for (int mask = 1; mask < (1<<n); mask++){
  	for (int b = 0; b < n; b++){
  		if (mask & (1<<b) && !ind[mask^(1<<b)]){
  			ind[mask] = 0;
  			break;
		  }
	  }
  }
  memset(dp, 0, sizeof dp);
  dp[0] = 1;
  for (int mask = 1; mask < (1<<n); mask++){
  	for (int subset = mask; subset; subset = (subset-1)&mask){
  		if (ind[subset]){
  			int bc = __builtin_popcount(subset);
  			if (bc&1) dp[mask] = (dp[mask]+dp[mask^subset])%mod;
  			else dp[mask] = (dp[mask]-dp[mask^subset]+mod)%mod;
  			
		  }
	  }
  }
  int full = (1<<n)-1;
  dp[full] = (dp[full]+mod)%mod;
  ll ans = dp[full]*m%mod*two_inv%mod;
 // for (int mask = 0; mask < (1<<n); mask++) cout << mask << ' ' << ind[mask] << '\n';
  cout << ans;
  
}
                 

Compilation message

amusementpark.cpp: In function 'void setIO(std::string)':
amusementpark.cpp:25:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  freopen((s+".in").c_str(), "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
amusementpark.cpp:26:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |  freopen((s+".out").c_str(), "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2472 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2472 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2472 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2492 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2392 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 2 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 1 ms 2492 KB Output is correct
59 Correct 1 ms 2392 KB Output is correct
60 Correct 1 ms 2396 KB Output is correct
61 Correct 1 ms 2396 KB Output is correct
62 Correct 1 ms 2392 KB Output is correct
63 Correct 1 ms 2396 KB Output is correct
64 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2472 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2492 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2392 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 2 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 1 ms 2492 KB Output is correct
59 Correct 1 ms 2392 KB Output is correct
60 Correct 1 ms 2396 KB Output is correct
61 Correct 1 ms 2396 KB Output is correct
62 Correct 1 ms 2392 KB Output is correct
63 Correct 1 ms 2396 KB Output is correct
64 Correct 1 ms 2396 KB Output is correct
65 Correct 8 ms 2504 KB Output is correct
66 Correct 7 ms 2396 KB Output is correct
67 Correct 6 ms 2396 KB Output is correct
68 Correct 8 ms 2396 KB Output is correct
69 Correct 13 ms 2396 KB Output is correct
70 Correct 10 ms 2488 KB Output is correct
71 Correct 12 ms 2396 KB Output is correct
72 Correct 10 ms 2516 KB Output is correct
73 Correct 8 ms 2396 KB Output is correct
74 Correct 8 ms 2396 KB Output is correct
75 Correct 8 ms 2440 KB Output is correct
76 Correct 8 ms 2396 KB Output is correct
77 Correct 21 ms 2396 KB Output is correct
78 Correct 20 ms 2396 KB Output is correct
79 Correct 19 ms 2532 KB Output is correct
80 Correct 17 ms 2532 KB Output is correct
81 Correct 17 ms 2392 KB Output is correct
82 Correct 17 ms 2392 KB Output is correct
83 Correct 16 ms 2396 KB Output is correct
84 Correct 15 ms 2392 KB Output is correct
85 Correct 41 ms 2396 KB Output is correct
86 Correct 27 ms 2504 KB Output is correct
87 Correct 28 ms 2396 KB Output is correct
88 Correct 29 ms 2396 KB Output is correct
89 Correct 22 ms 2396 KB Output is correct
90 Correct 23 ms 2396 KB Output is correct
91 Correct 23 ms 2396 KB Output is correct
92 Correct 24 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2472 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2492 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2392 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 2 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 1 ms 2492 KB Output is correct
59 Correct 1 ms 2392 KB Output is correct
60 Correct 1 ms 2396 KB Output is correct
61 Correct 1 ms 2396 KB Output is correct
62 Correct 1 ms 2392 KB Output is correct
63 Correct 1 ms 2396 KB Output is correct
64 Correct 1 ms 2396 KB Output is correct
65 Correct 8 ms 2504 KB Output is correct
66 Correct 7 ms 2396 KB Output is correct
67 Correct 6 ms 2396 KB Output is correct
68 Correct 8 ms 2396 KB Output is correct
69 Correct 13 ms 2396 KB Output is correct
70 Correct 10 ms 2488 KB Output is correct
71 Correct 12 ms 2396 KB Output is correct
72 Correct 10 ms 2516 KB Output is correct
73 Correct 8 ms 2396 KB Output is correct
74 Correct 8 ms 2396 KB Output is correct
75 Correct 8 ms 2440 KB Output is correct
76 Correct 8 ms 2396 KB Output is correct
77 Correct 21 ms 2396 KB Output is correct
78 Correct 20 ms 2396 KB Output is correct
79 Correct 19 ms 2532 KB Output is correct
80 Correct 17 ms 2532 KB Output is correct
81 Correct 17 ms 2392 KB Output is correct
82 Correct 17 ms 2392 KB Output is correct
83 Correct 16 ms 2396 KB Output is correct
84 Correct 15 ms 2392 KB Output is correct
85 Correct 41 ms 2396 KB Output is correct
86 Correct 27 ms 2504 KB Output is correct
87 Correct 28 ms 2396 KB Output is correct
88 Correct 29 ms 2396 KB Output is correct
89 Correct 22 ms 2396 KB Output is correct
90 Correct 23 ms 2396 KB Output is correct
91 Correct 23 ms 2396 KB Output is correct
92 Correct 24 ms 2392 KB Output is correct
93 Correct 790 ms 2720 KB Output is correct
94 Correct 749 ms 2720 KB Output is correct
95 Correct 765 ms 2716 KB Output is correct
96 Correct 593 ms 2724 KB Output is correct
97 Correct 566 ms 2904 KB Output is correct
98 Correct 616 ms 2648 KB Output is correct
99 Correct 67 ms 2396 KB Output is correct
100 Correct 58 ms 2540 KB Output is correct
101 Correct 53 ms 2392 KB Output is correct
102 Correct 50 ms 2396 KB Output is correct
103 Correct 424 ms 2396 KB Output is correct
104 Correct 250 ms 2600 KB Output is correct
105 Correct 219 ms 2396 KB Output is correct
106 Correct 167 ms 2648 KB Output is correct
107 Correct 1309 ms 2720 KB Output is correct
108 Correct 609 ms 2648 KB Output is correct
109 Correct 470 ms 2648 KB Output is correct
110 Correct 421 ms 2652 KB Output is correct
111 Correct 50 ms 2392 KB Output is correct
112 Correct 46 ms 2392 KB Output is correct
113 Correct 43 ms 2392 KB Output is correct
114 Correct 107 ms 2532 KB Output is correct
115 Correct 96 ms 2392 KB Output is correct
116 Correct 86 ms 2396 KB Output is correct
117 Correct 83 ms 2392 KB Output is correct
118 Correct 67 ms 2392 KB Output is correct
119 Correct 68 ms 2544 KB Output is correct
120 Correct 68 ms 2396 KB Output is correct
121 Correct 67 ms 2396 KB Output is correct
122 Correct 152 ms 2392 KB Output is correct
123 Correct 142 ms 2640 KB Output is correct
124 Correct 129 ms 2396 KB Output is correct
125 Correct 136 ms 2392 KB Output is correct
126 Correct 121 ms 2596 KB Output is correct
127 Correct 120 ms 2600 KB Output is correct
128 Correct 113 ms 2396 KB Output is correct
129 Correct 111 ms 2392 KB Output is correct
130 Correct 106 ms 2392 KB Output is correct
131 Correct 315 ms 2600 KB Output is correct
132 Correct 240 ms 2396 KB Output is correct
133 Correct 241 ms 2600 KB Output is correct
134 Correct 244 ms 2652 KB Output is correct
135 Correct 196 ms 2644 KB Output is correct
136 Correct 194 ms 2600 KB Output is correct
137 Correct 199 ms 2396 KB Output is correct
138 Correct 225 ms 2600 KB Output is correct
139 Correct 165 ms 2596 KB Output is correct
140 Correct 181 ms 2396 KB Output is correct
141 Correct 168 ms 2856 KB Output is correct
142 Correct 385 ms 2652 KB Output is correct
143 Correct 362 ms 2648 KB Output is correct
144 Correct 348 ms 2896 KB Output is correct
145 Correct 350 ms 2652 KB Output is correct
146 Correct 324 ms 2904 KB Output is correct
147 Correct 317 ms 2648 KB Output is correct
148 Correct 387 ms 2652 KB Output is correct
149 Correct 400 ms 2724 KB Output is correct
150 Correct 374 ms 2724 KB Output is correct
151 Correct 469 ms 2652 KB Output is correct
152 Correct 459 ms 2900 KB Output is correct
153 Correct 585 ms 2652 KB Output is correct
154 Correct 598 ms 2652 KB Output is correct
155 Correct 604 ms 2724 KB Output is correct
156 Correct 591 ms 2720 KB Output is correct
157 Correct 587 ms 2652 KB Output is correct
158 Correct 588 ms 2724 KB Output is correct
159 Correct 502 ms 2720 KB Output is correct
160 Correct 485 ms 2652 KB Output is correct
161 Correct 519 ms 2652 KB Output is correct
162 Correct 445 ms 2652 KB Output is correct
163 Correct 436 ms 2648 KB Output is correct
164 Correct 431 ms 2900 KB Output is correct
165 Correct 434 ms 2720 KB Output is correct
166 Correct 432 ms 2648 KB Output is correct
167 Correct 453 ms 2720 KB Output is correct