Submission #1003658

# Submission time Handle Problem Language Result Execution time Memory
1003658 2024-06-20T14:45:06 Z GrindMachine Amusement Park (CEOI19_amusementpark) C++17
100 / 100
1354 ms 223208 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)

template<typename T>
void amin(T &a, T b) {
    a = min(a,b);
}

template<typename T>
void amax(T &a, T b) {
    a = max(a,b);
}

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

/*

read the solution a long time ago and remember some ideas from there

*/

const int MOD = 998244353;
const int N = 20 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;

vector<pii> adj[N];

void solve(int test_case)
{
    int n,m; cin >> n >> m;
    rep1(i,m){
        int u,v; cin >> u >> v;
        u--, v--;
        adj[u].pb({v,0}), adj[v].pb({u,1});
    }

    unordered_map<int,int> dp[1<<n];
    dp[0][0] = 1;

    rep(mask,1<<n){
        ll unset = ((1<<n)-1)^mask;
        for(auto [bad,x] : dp[mask]){
            rep(u,n){
                if(mask&(1<<u) or bad&(1<<u)) conts;
                int mask2 = mask|(1<<u);
                int bad2 = bad;
                bad2 |= (1<<u)-1;
                bad2 &= unset;

                for(auto [v,t] : adj[u]){
                    if(mask&(1<<v)) conts;
                    if(bad2&(1<<v)){
                        bad2 ^= (1<<v);
                    }
                }

                dp[mask2][bad2] += x;
                dp[mask2][bad2] %= MOD;
            }
        }
    }

    ll ans = dp[(1<<n)-1][0];
    ans = ans*m%MOD*((MOD+1)/2)%MOD;
    cout << ans << endl;
}

int main()
{
    fastio;

    int t = 1;
    // cin >> t;

    rep1(i, t) {
        solve(i);
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 344 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 604 KB Output is correct
53 Correct 1 ms 600 KB Output is correct
54 Correct 1 ms 856 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 600 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 604 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 1 ms 604 KB Output is correct
64 Correct 1 ms 680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 344 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 604 KB Output is correct
53 Correct 1 ms 600 KB Output is correct
54 Correct 1 ms 856 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 600 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 604 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 1 ms 604 KB Output is correct
64 Correct 1 ms 680 KB Output is correct
65 Correct 20 ms 6236 KB Output is correct
66 Correct 31 ms 7260 KB Output is correct
67 Correct 33 ms 6748 KB Output is correct
68 Correct 34 ms 6484 KB Output is correct
69 Correct 8 ms 4188 KB Output is correct
70 Correct 16 ms 4700 KB Output is correct
71 Correct 12 ms 4516 KB Output is correct
72 Correct 12 ms 4572 KB Output is correct
73 Correct 15 ms 4696 KB Output is correct
74 Correct 15 ms 4776 KB Output is correct
75 Correct 15 ms 4696 KB Output is correct
76 Correct 15 ms 4700 KB Output is correct
77 Correct 45 ms 13648 KB Output is correct
78 Correct 58 ms 14676 KB Output is correct
79 Correct 86 ms 17256 KB Output is correct
80 Correct 68 ms 14584 KB Output is correct
81 Correct 85 ms 15952 KB Output is correct
82 Correct 82 ms 14416 KB Output is correct
83 Correct 79 ms 13908 KB Output is correct
84 Correct 69 ms 11612 KB Output is correct
85 Correct 21 ms 8344 KB Output is correct
86 Correct 24 ms 9048 KB Output is correct
87 Correct 24 ms 9120 KB Output is correct
88 Correct 33 ms 9096 KB Output is correct
89 Correct 30 ms 9300 KB Output is correct
90 Correct 31 ms 9300 KB Output is correct
91 Correct 30 ms 9216 KB Output is correct
92 Correct 30 ms 9128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 344 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 604 KB Output is correct
53 Correct 1 ms 600 KB Output is correct
54 Correct 1 ms 856 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 600 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 604 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 1 ms 604 KB Output is correct
64 Correct 1 ms 680 KB Output is correct
65 Correct 20 ms 6236 KB Output is correct
66 Correct 31 ms 7260 KB Output is correct
67 Correct 33 ms 6748 KB Output is correct
68 Correct 34 ms 6484 KB Output is correct
69 Correct 8 ms 4188 KB Output is correct
70 Correct 16 ms 4700 KB Output is correct
71 Correct 12 ms 4516 KB Output is correct
72 Correct 12 ms 4572 KB Output is correct
73 Correct 15 ms 4696 KB Output is correct
74 Correct 15 ms 4776 KB Output is correct
75 Correct 15 ms 4696 KB Output is correct
76 Correct 15 ms 4700 KB Output is correct
77 Correct 45 ms 13648 KB Output is correct
78 Correct 58 ms 14676 KB Output is correct
79 Correct 86 ms 17256 KB Output is correct
80 Correct 68 ms 14584 KB Output is correct
81 Correct 85 ms 15952 KB Output is correct
82 Correct 82 ms 14416 KB Output is correct
83 Correct 79 ms 13908 KB Output is correct
84 Correct 69 ms 11612 KB Output is correct
85 Correct 21 ms 8344 KB Output is correct
86 Correct 24 ms 9048 KB Output is correct
87 Correct 24 ms 9120 KB Output is correct
88 Correct 33 ms 9096 KB Output is correct
89 Correct 30 ms 9300 KB Output is correct
90 Correct 31 ms 9300 KB Output is correct
91 Correct 30 ms 9216 KB Output is correct
92 Correct 30 ms 9128 KB Output is correct
93 Correct 289 ms 74752 KB Output is correct
94 Correct 131 ms 56516 KB Output is correct
95 Correct 105 ms 52564 KB Output is correct
96 Correct 381 ms 76628 KB Output is correct
97 Correct 350 ms 76372 KB Output is correct
98 Correct 308 ms 74068 KB Output is correct
99 Correct 67 ms 22616 KB Output is correct
100 Correct 108 ms 30288 KB Output is correct
101 Correct 169 ms 36808 KB Output is correct
102 Correct 202 ms 38736 KB Output is correct
103 Correct 52 ms 25936 KB Output is correct
104 Correct 37 ms 26424 KB Output is correct
105 Correct 68 ms 34132 KB Output is correct
106 Correct 253 ms 61704 KB Output is correct
107 Correct 73 ms 51552 KB Output is correct
108 Correct 156 ms 71508 KB Output is correct
109 Correct 588 ms 131968 KB Output is correct
110 Correct 1327 ms 223208 KB Output is correct
111 Correct 236 ms 38224 KB Output is correct
112 Correct 170 ms 31472 KB Output is correct
113 Correct 190 ms 30076 KB Output is correct
114 Correct 36 ms 16744 KB Output is correct
115 Correct 56 ms 18008 KB Output is correct
116 Correct 56 ms 18256 KB Output is correct
117 Correct 49 ms 18056 KB Output is correct
118 Correct 65 ms 18516 KB Output is correct
119 Correct 67 ms 18512 KB Output is correct
120 Correct 67 ms 18512 KB Output is correct
121 Correct 68 ms 18516 KB Output is correct
122 Correct 332 ms 67016 KB Output is correct
123 Correct 518 ms 85628 KB Output is correct
124 Correct 548 ms 80720 KB Output is correct
125 Correct 509 ms 74324 KB Output is correct
126 Correct 472 ms 66472 KB Output is correct
127 Correct 341 ms 49632 KB Output is correct
128 Correct 303 ms 39880 KB Output is correct
129 Correct 206 ms 32848 KB Output is correct
130 Correct 117 ms 25952 KB Output is correct
131 Correct 90 ms 33620 KB Output is correct
132 Correct 131 ms 36640 KB Output is correct
133 Correct 122 ms 36688 KB Output is correct
134 Correct 123 ms 36688 KB Output is correct
135 Correct 156 ms 37608 KB Output is correct
136 Correct 185 ms 37716 KB Output is correct
137 Correct 141 ms 37712 KB Output is correct
138 Correct 128 ms 37576 KB Output is correct
139 Correct 182 ms 37504 KB Output is correct
140 Correct 154 ms 37456 KB Output is correct
141 Correct 147 ms 37456 KB Output is correct
142 Correct 1179 ms 187868 KB Output is correct
143 Correct 1304 ms 174932 KB Output is correct
144 Correct 1006 ms 130896 KB Output is correct
145 Correct 806 ms 103240 KB Output is correct
146 Correct 564 ms 73868 KB Output is correct
147 Correct 213 ms 51648 KB Output is correct
148 Correct 1180 ms 178668 KB Output is correct
149 Correct 1114 ms 174676 KB Output is correct
150 Correct 1354 ms 196624 KB Output is correct
151 Correct 243 ms 75348 KB Output is correct
152 Correct 252 ms 77408 KB Output is correct
153 Correct 344 ms 76704 KB Output is correct
154 Correct 315 ms 76624 KB Output is correct
155 Correct 324 ms 76628 KB Output is correct
156 Correct 318 ms 77048 KB Output is correct
157 Correct 348 ms 76624 KB Output is correct
158 Correct 315 ms 76624 KB Output is correct
159 Correct 373 ms 76628 KB Output is correct
160 Correct 371 ms 76744 KB Output is correct
161 Correct 375 ms 76508 KB Output is correct
162 Correct 417 ms 75604 KB Output is correct
163 Correct 409 ms 75348 KB Output is correct
164 Correct 398 ms 75412 KB Output is correct
165 Correct 393 ms 75344 KB Output is correct
166 Correct 397 ms 75652 KB Output is correct
167 Correct 381 ms 75436 KB Output is correct