Submission #927599

# Submission time Handle Problem Language Result Execution time Memory
927599 2024-02-15T07:01:37 Z Pragmatism Paths (BOI18_paths) C++17
100 / 100
280 ms 98300 KB
//Bismillahir-Rahmanir-Rahim

#include <bits/stdc++.h>
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,sse4.1,sse4.2,popcnt,avx,avx2")

#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long>
#define pld pair <long double, long double>
#define ll long long
#define ld long double
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define sz(s) (int)s.size()
#define skip continue
#define bpop(x) (ll)__builtin_popcountll(x)

using namespace std;

const int N = 3e5 + 7;
const int M = 5e3 + 7;
const int maxA = 2e6 + 7;
const int inf = 1e9 + 7;
const ll INF = 2e18 + 7;
const int MOD = 1e9 + 7;
const ld eps = 1e-9;

pii dir[] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define int long long

vector <int> g[N];
int n, m, k, a[N], dp[N][33];
void solve() {
    cin >> n >> m >> k;
    for (int i = 1;i <= n;i++)cin >> a[i], a[i]--;
    for (int i = 1;i <= m;i++) {
        int x, y;
        cin >> x >> y;
        g[x].pb(y), g[y].pb(x);
    }
    int ans = 0;
    for (int i = 1;i <= n;i++)dp[i][(1ll << a[i])]++;
    for (int mask = 0;mask < (1ll << k);mask++) {
        for (int v = 1;v <= n;v++) {
            if (dp[v][mask]) {
                for (auto to : g[v]) {
                    if (mask & (1ll << a[to]))skip;
                    dp[to][mask + (1ll << a[to])] += dp[v][mask];
                }
            }
        }
        for (int i = 1;i <= n;i++)ans += dp[i][mask];
    }
    cout << ans - n;
}
signed main() {
    //srand(time(NULL));
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    //freopen("tests.in", "r", stdin);
    //freopen("milkorder.out", "w", stdout);
    int test = 1;
    //cin >> test;
    for (int t = 1;t <= test;t++) {
        //cout << "Case " << t << ": ";
        solve();
    }
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 11100 KB Output is correct
2 Correct 3 ms 11100 KB Output is correct
3 Correct 2 ms 11100 KB Output is correct
4 Correct 2 ms 11100 KB Output is correct
5 Correct 2 ms 11100 KB Output is correct
6 Correct 2 ms 11100 KB Output is correct
7 Correct 2 ms 11100 KB Output is correct
8 Correct 2 ms 11100 KB Output is correct
9 Correct 3 ms 11100 KB Output is correct
10 Correct 2 ms 11100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 20564 KB Output is correct
2 Correct 44 ms 20596 KB Output is correct
3 Correct 226 ms 97620 KB Output is correct
4 Correct 72 ms 27704 KB Output is correct
5 Correct 68 ms 27732 KB Output is correct
6 Correct 136 ms 73488 KB Output is correct
7 Correct 212 ms 97616 KB Output is correct
8 Correct 187 ms 98280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11100 KB Output is correct
2 Correct 3 ms 11100 KB Output is correct
3 Correct 2 ms 11100 KB Output is correct
4 Correct 2 ms 11100 KB Output is correct
5 Correct 2 ms 11100 KB Output is correct
6 Correct 2 ms 11100 KB Output is correct
7 Correct 2 ms 11100 KB Output is correct
8 Correct 2 ms 11100 KB Output is correct
9 Correct 3 ms 11100 KB Output is correct
10 Correct 2 ms 11100 KB Output is correct
11 Correct 55 ms 20564 KB Output is correct
12 Correct 44 ms 20596 KB Output is correct
13 Correct 226 ms 97620 KB Output is correct
14 Correct 72 ms 27704 KB Output is correct
15 Correct 68 ms 27732 KB Output is correct
16 Correct 136 ms 73488 KB Output is correct
17 Correct 212 ms 97616 KB Output is correct
18 Correct 187 ms 98280 KB Output is correct
19 Correct 54 ms 20656 KB Output is correct
20 Correct 45 ms 20448 KB Output is correct
21 Correct 204 ms 97872 KB Output is correct
22 Correct 77 ms 27656 KB Output is correct
23 Correct 64 ms 27620 KB Output is correct
24 Correct 135 ms 73588 KB Output is correct
25 Correct 201 ms 97952 KB Output is correct
26 Correct 200 ms 98300 KB Output is correct
27 Correct 55 ms 20568 KB Output is correct
28 Correct 72 ms 22040 KB Output is correct
29 Correct 280 ms 98192 KB Output is correct
30 Correct 163 ms 59072 KB Output is correct
31 Correct 237 ms 59188 KB Output is correct
32 Correct 269 ms 97868 KB Output is correct
33 Correct 2 ms 11096 KB Output is correct
34 Correct 2 ms 11100 KB Output is correct
35 Correct 3 ms 11100 KB Output is correct
36 Correct 3 ms 11100 KB Output is correct
37 Correct 2 ms 11100 KB Output is correct
38 Correct 2 ms 11100 KB Output is correct
39 Correct 2 ms 11100 KB Output is correct
40 Correct 2 ms 11100 KB Output is correct
41 Correct 2 ms 11096 KB Output is correct
42 Correct 2 ms 11100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11100 KB Output is correct
2 Correct 26 ms 13404 KB Output is correct
3 Correct 18 ms 13404 KB Output is correct
4 Correct 49 ms 41540 KB Output is correct
5 Correct 40 ms 41928 KB Output is correct
6 Correct 84 ms 41596 KB Output is correct
7 Correct 22 ms 13404 KB Output is correct
8 Correct 58 ms 41552 KB Output is correct
9 Correct 59 ms 41932 KB Output is correct
10 Correct 54 ms 41668 KB Output is correct
11 Correct 50 ms 28372 KB Output is correct
12 Correct 52 ms 34892 KB Output is correct
13 Correct 51 ms 28420 KB Output is correct
14 Correct 78 ms 41592 KB Output is correct
15 Correct 78 ms 41676 KB Output is correct
16 Correct 2 ms 11100 KB Output is correct
17 Correct 2 ms 11100 KB Output is correct
18 Correct 2 ms 11100 KB Output is correct
19 Correct 2 ms 11100 KB Output is correct
20 Correct 3 ms 11100 KB Output is correct
21 Correct 2 ms 11100 KB Output is correct
22 Correct 3 ms 11100 KB Output is correct
23 Correct 3 ms 11100 KB Output is correct
24 Correct 2 ms 11100 KB Output is correct
25 Correct 3 ms 11100 KB Output is correct