Submission #601727

# Submission time Handle Problem Language Result Execution time Memory
601727 2022-07-22T09:26:05 Z ktkerem Paths (BOI18_paths) C++17
100 / 100
501 ms 102744 KB
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
/*#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
template<class T>
using oset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
/**/
//typedef int ll;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 vll;
typedef unsigned __int128 uvll;
ll _i=0;
#define ffn(x) _i=x
#define llll std::pair<ll , ll>
#define stitr set<ll>::iterator
#define fora(y,x) for(ll y=_i;x>y;y++)
#define pb push_back
#define pf push_front
#define halo cout << "hello\n"
#define fi first
#define sec second
#define all(a) a.begin() , a.end()
const ll limit = 1e9+7; 
const ll ous = 2e5 + 7;
const ll dx[4] = {1 , 0 , 0 , -1} , dy[4] = {0,1,-1,0};
void solve(){
    ll n , m , k;std::cin >> n >> m >> k;
    ll ar[n];
    ll dp[n+1][33];
    memset(dp , 0 , sizeof(dp));
    std::vector<ll> v[k + 2] , adj[n+5];
    fora(i , n){
        std::cin >> ar[i];
    }
    fora(i , (1 << k)){
        ll s = __builtin_popcount(i);
        v[s].pb(i);
    }
    fora(i , n){
        dp[i][(1 << (ar[i] - 1))] = 1;
    }
    fora(i , m){
        ll x , y;std::cin >> x >> y;
        x--;y--;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    for(ll o = 2;k>=o;o++){
        fora(i , n){
            for(auto j:adj[i]){
                for(auto vl:v[o - 1]){
                    if(vl & (1 << (ar[i] - 1))){
                        continue;
                    }
                    dp[i][vl | (1 << (ar[i] - 1))] += dp[j][vl];
                }
            }
        }
    }
    ll ans = 0;
    fora(i , n){
        for(ll j = 2;k>=j;j++){
            for(auto o:v[j]){
                ans+=dp[i][o];
            }
        }
    }
    std::cout << ans << "\n";
    return;/**/
}
signed main(){
    std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
    ll t=1;
   // std::cin >> t;
    ll o = 1;
    while(t--){ 
        //cout << "Case " << o++ << ":\n";
        solve();
    }
    return 0; 
}

Compilation message

paths.cpp:12:1: warning: "/*" within comment [-Wcomment]
   12 | /**/
      |  
paths.cpp: In function 'int main()':
paths.cpp:81:8: warning: unused variable 'o' [-Wunused-variable]
   81 |     ll o = 1;
      |        ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 236 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 11772 KB Output is correct
2 Correct 82 ms 9960 KB Output is correct
3 Correct 427 ms 102196 KB Output is correct
4 Correct 163 ms 20440 KB Output is correct
5 Correct 119 ms 20408 KB Output is correct
6 Correct 228 ms 71092 KB Output is correct
7 Correct 311 ms 102196 KB Output is correct
8 Correct 313 ms 102632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 236 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 106 ms 11772 KB Output is correct
12 Correct 82 ms 9960 KB Output is correct
13 Correct 427 ms 102196 KB Output is correct
14 Correct 163 ms 20440 KB Output is correct
15 Correct 119 ms 20408 KB Output is correct
16 Correct 228 ms 71092 KB Output is correct
17 Correct 311 ms 102196 KB Output is correct
18 Correct 313 ms 102632 KB Output is correct
19 Correct 102 ms 11752 KB Output is correct
20 Correct 81 ms 9872 KB Output is correct
21 Correct 344 ms 102192 KB Output is correct
22 Correct 142 ms 20400 KB Output is correct
23 Correct 129 ms 20420 KB Output is correct
24 Correct 283 ms 71176 KB Output is correct
25 Correct 385 ms 102192 KB Output is correct
26 Correct 394 ms 102744 KB Output is correct
27 Correct 74 ms 9808 KB Output is correct
28 Correct 111 ms 14072 KB Output is correct
29 Correct 444 ms 102232 KB Output is correct
30 Correct 283 ms 56508 KB Output is correct
31 Correct 273 ms 56572 KB Output is correct
32 Correct 501 ms 102220 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 328 KB Output is correct
35 Correct 1 ms 320 KB Output is correct
36 Correct 1 ms 380 KB Output is correct
37 Correct 1 ms 368 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 360 KB Output is correct
40 Correct 1 ms 436 KB Output is correct
41 Correct 1 ms 352 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 36 ms 3328 KB Output is correct
3 Correct 27 ms 3364 KB Output is correct
4 Correct 83 ms 34120 KB Output is correct
5 Correct 93 ms 34500 KB Output is correct
6 Correct 192 ms 34128 KB Output is correct
7 Correct 46 ms 3360 KB Output is correct
8 Correct 140 ms 34128 KB Output is correct
9 Correct 92 ms 34532 KB Output is correct
10 Correct 100 ms 34644 KB Output is correct
11 Correct 75 ms 18520 KB Output is correct
12 Correct 85 ms 26352 KB Output is correct
13 Correct 80 ms 18896 KB Output is correct
14 Correct 189 ms 34120 KB Output is correct
15 Correct 152 ms 34092 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct