Submission #927207

# Submission time Handle Problem Language Result Execution time Memory
927207 2024-02-14T12:12:12 Z vjudge1 Paths (BOI18_paths) C++17
100 / 100
189 ms 249368 KB
// By ObeliX
#include <bits/stdc++.h>
#pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include <unordered_map>
#include <cstddef>
#include <cassert>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>

using namespace std;

const long long N = 3e5 + 5;
const long long MOD = 1e9+7;
const long long INF = 1e18;

string al = "abcdefghijklmnopqrstuvwxyz";

long long n , m , k;
long long col[N];
long long x[N] , y[N];

long long dp[N][103];

int main(){
    //freopen( "cinema.in" , "r" , stdin );
    //freopen( "cinema.out" , "w" , stdout );
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> k;
    for ( int i = 1 ; i <= n ; i++ ) {
        cin >> col[i];
        dp[i][(1 << ( col[i] - 1 ))] = 1;
    }
    for ( int i = 1 ; i <= m ; i++ ) {
        cin >> x[i] >> y[i];
    }
    for ( int mask = 1 ; mask <= ( 1 << k ) - 1 ; mask++ ) {
        for ( int i = 1 ; i <= m ; i++ ) {
            if ( ( mask & ( 1 << ( col[x[i]] - 1 ) ) ) == 1 << ( col[x[i]] - 1 ) && ( mask & ( 1 << ( col[y[i]] - 1 ) ) ) == 0 ) {
                dp[y[i]][mask|1<<(col[y[i]] - 1)] += dp[x[i]][mask];
            }
            if ( ( mask & ( 1 << ( col[x[i]] - 1 ) ) ) == 0 && ( mask & ( 1 << ( col[y[i]] - 1 ) ) ) == 1 << ( col[y[i]] - 1 ) ) {
                dp[x[i]][mask|1<<(col[x[i]] - 1)] += dp[y[i]][mask];
            }
        }
    }
    long long ans = 0;
    for ( int mask = 1 ; mask <= ( 1 << k ) - 1 ; mask++ ) {
        for ( int i = 1 ; i <= n ; i++ ) {
            ans += dp[i][mask];
        }
    }
    cout << ans - n;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6740 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6668 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 12892 KB Output is correct
2 Correct 44 ms 10844 KB Output is correct
3 Correct 151 ms 249364 KB Output is correct
4 Correct 48 ms 33368 KB Output is correct
5 Correct 39 ms 33372 KB Output is correct
6 Correct 97 ms 170936 KB Output is correct
7 Correct 123 ms 249172 KB Output is correct
8 Correct 119 ms 249364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6740 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6668 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 48 ms 12892 KB Output is correct
12 Correct 44 ms 10844 KB Output is correct
13 Correct 151 ms 249364 KB Output is correct
14 Correct 48 ms 33368 KB Output is correct
15 Correct 39 ms 33372 KB Output is correct
16 Correct 97 ms 170936 KB Output is correct
17 Correct 123 ms 249172 KB Output is correct
18 Correct 119 ms 249364 KB Output is correct
19 Correct 50 ms 13136 KB Output is correct
20 Correct 43 ms 10844 KB Output is correct
21 Correct 125 ms 249300 KB Output is correct
22 Correct 46 ms 33372 KB Output is correct
23 Correct 38 ms 33372 KB Output is correct
24 Correct 96 ms 170944 KB Output is correct
25 Correct 119 ms 249164 KB Output is correct
26 Correct 132 ms 249364 KB Output is correct
27 Correct 65 ms 10844 KB Output is correct
28 Correct 70 ms 16988 KB Output is correct
29 Correct 189 ms 249364 KB Output is correct
30 Correct 129 ms 129648 KB Output is correct
31 Correct 138 ms 129884 KB Output is correct
32 Correct 185 ms 249368 KB Output is correct
33 Correct 1 ms 6488 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 1 ms 6492 KB Output is correct
36 Correct 1 ms 6492 KB Output is correct
37 Correct 1 ms 6492 KB Output is correct
38 Correct 1 ms 6492 KB Output is correct
39 Correct 1 ms 6492 KB Output is correct
40 Correct 1 ms 6492 KB Output is correct
41 Correct 1 ms 6492 KB Output is correct
42 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 36 ms 10844 KB Output is correct
3 Correct 16 ms 10844 KB Output is correct
4 Correct 37 ms 90716 KB Output is correct
5 Correct 35 ms 90716 KB Output is correct
6 Correct 77 ms 90716 KB Output is correct
7 Correct 22 ms 10844 KB Output is correct
8 Correct 49 ms 90716 KB Output is correct
9 Correct 45 ms 90716 KB Output is correct
10 Correct 53 ms 90716 KB Output is correct
11 Correct 59 ms 50004 KB Output is correct
12 Correct 65 ms 70388 KB Output is correct
13 Correct 53 ms 49752 KB Output is correct
14 Correct 74 ms 90716 KB Output is correct
15 Correct 72 ms 90928 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct