Submission #1078671

# Submission time Handle Problem Language Result Execution time Memory
1078671 2024-08-28T04:00:32 Z steveonalex Paths (BOI18_paths) C++17
100 / 100
208 ms 59008 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
#define block_of_code if(true)
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
 
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
 
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
double rngesus_d(double l, double r){
    double cur = rngesus(0, MASK(60) - 1);
    cur /= MASK(60) - 1;
    return l + cur * (r - l);
}
 
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }
 
template <class T>
    void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }
 
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

const int N = 3e5 + 69;
int n, m, k; 
vector<int> graph[N];
int color[N];

int main(void){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    clock_t start = clock();

    cin >> n >> m >> k;
    for(int i = 1; i<=n; ++i){
        cin >> color[i];
        color[i]--;
    }

    for(int i = 1; i<=m; ++i){
        int u, v; cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    ll dp[MASK(k)][n+1];
    memset(dp, 0, sizeof dp);
    for(int i = 1; i<=n; ++i) dp[MASK(color[i])][i] = 1;

    ll ans = 0;
    for(int mask = 1; mask < MASK(k); ++mask){
        for(int i = 1; i<=n; ++i) if (dp[mask][i]){
            if (pop_cnt(mask) > 1) ans += dp[mask][i];
            for(int j: graph[i]) if (!GETBIT(mask, color[j])){
                dp[mask + MASK(color[j])][j] += dp[mask][i];
            }
        }
    }

    cout << ans << "\n";

    cerr << "Time elapsed: " << clock() - start << " ms\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7768 KB Output is correct
2 Correct 4 ms 7512 KB Output is correct
3 Correct 4 ms 7516 KB Output is correct
4 Correct 3 ms 7516 KB Output is correct
5 Correct 3 ms 7516 KB Output is correct
6 Correct 3 ms 7516 KB Output is correct
7 Correct 3 ms 7516 KB Output is correct
8 Correct 3 ms 7512 KB Output is correct
9 Correct 3 ms 7516 KB Output is correct
10 Correct 4 ms 7308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 14168 KB Output is correct
2 Correct 40 ms 13396 KB Output is correct
3 Correct 152 ms 40316 KB Output is correct
4 Correct 64 ms 16256 KB Output is correct
5 Correct 56 ms 15840 KB Output is correct
6 Correct 123 ms 31956 KB Output is correct
7 Correct 147 ms 40112 KB Output is correct
8 Correct 148 ms 40788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7768 KB Output is correct
2 Correct 4 ms 7512 KB Output is correct
3 Correct 4 ms 7516 KB Output is correct
4 Correct 3 ms 7516 KB Output is correct
5 Correct 3 ms 7516 KB Output is correct
6 Correct 3 ms 7516 KB Output is correct
7 Correct 3 ms 7516 KB Output is correct
8 Correct 3 ms 7512 KB Output is correct
9 Correct 3 ms 7516 KB Output is correct
10 Correct 4 ms 7308 KB Output is correct
11 Correct 55 ms 14168 KB Output is correct
12 Correct 40 ms 13396 KB Output is correct
13 Correct 152 ms 40316 KB Output is correct
14 Correct 64 ms 16256 KB Output is correct
15 Correct 56 ms 15840 KB Output is correct
16 Correct 123 ms 31956 KB Output is correct
17 Correct 147 ms 40112 KB Output is correct
18 Correct 148 ms 40788 KB Output is correct
19 Correct 50 ms 14076 KB Output is correct
20 Correct 40 ms 13392 KB Output is correct
21 Correct 145 ms 40088 KB Output is correct
22 Correct 66 ms 16208 KB Output is correct
23 Correct 57 ms 15696 KB Output is correct
24 Correct 122 ms 31940 KB Output is correct
25 Correct 150 ms 40280 KB Output is correct
26 Correct 140 ms 40788 KB Output is correct
27 Correct 50 ms 13404 KB Output is correct
28 Correct 67 ms 15696 KB Output is correct
29 Correct 191 ms 59008 KB Output is correct
30 Correct 126 ms 36548 KB Output is correct
31 Correct 126 ms 36552 KB Output is correct
32 Correct 208 ms 58960 KB Output is correct
33 Correct 4 ms 7512 KB Output is correct
34 Correct 3 ms 7516 KB Output is correct
35 Correct 3 ms 7260 KB Output is correct
36 Correct 3 ms 7516 KB Output is correct
37 Correct 3 ms 7516 KB Output is correct
38 Correct 3 ms 7516 KB Output is correct
39 Correct 4 ms 7512 KB Output is correct
40 Correct 4 ms 7508 KB Output is correct
41 Correct 3 ms 7512 KB Output is correct
42 Correct 4 ms 7512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7512 KB Output is correct
2 Correct 25 ms 9308 KB Output is correct
3 Correct 16 ms 9308 KB Output is correct
4 Correct 55 ms 18256 KB Output is correct
5 Correct 33 ms 18892 KB Output is correct
6 Correct 70 ms 36972 KB Output is correct
7 Correct 20 ms 9236 KB Output is correct
8 Correct 48 ms 24360 KB Output is correct
9 Correct 38 ms 25312 KB Output is correct
10 Correct 44 ms 24936 KB Output is correct
11 Correct 50 ms 23072 KB Output is correct
12 Correct 44 ms 30540 KB Output is correct
13 Correct 47 ms 23116 KB Output is correct
14 Correct 81 ms 36904 KB Output is correct
15 Correct 67 ms 37200 KB Output is correct
16 Correct 3 ms 7516 KB Output is correct
17 Correct 5 ms 7512 KB Output is correct
18 Correct 4 ms 7512 KB Output is correct
19 Correct 4 ms 7484 KB Output is correct
20 Correct 4 ms 7516 KB Output is correct
21 Correct 3 ms 7516 KB Output is correct
22 Correct 4 ms 7468 KB Output is correct
23 Correct 3 ms 7512 KB Output is correct
24 Correct 4 ms 7260 KB Output is correct
25 Correct 3 ms 7260 KB Output is correct