답안 #941007

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
941007 2024-03-08T04:59:05 Z phoenix0423 Paths (BOI18_paths) C++17
100 / 100
468 ms 100692 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define int long long
#define lowbit(x) x&-x
const int maxn = 3e5 + 5;
vector<int> adj[maxn];
int c[maxn];
int n, m, k;
int dp[maxn][32];

signed main(void){
    fastio;
    cin>>n>>m>>k;
    for(int i = 0; i < n; i++) cin>>c[i], c[i]--;
    for(int i = 0; i < m; i++){
        int a, b;
        cin>>a>>b;
        a--, b--;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    for(int i = 0; i < n; i++) dp[i][(1 << c[i])] = 1;
    int ans = 0;
    for(int rd = 1; rd < k; rd++){
        for(int i = 0; i < n; i++){
            for(int mask = 0; mask < (1 << k); mask++){
                if(__builtin_popcount(mask) != rd) continue;
                if(!dp[i][mask]) continue;
                for(auto x : adj[i]){
                    if(mask & (1 << c[x])) continue;
                    dp[x][mask | (1 << c[x])] += dp[i][mask];
                }
            }
        }
    }
    for(int i = 0; i < n; i++){
        for(int mask = 1; mask < (1 << k); mask++){
            if(__builtin_popcount(mask) == 1) continue;
            ans += dp[i][mask];
        }
    }
    cout<<ans<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 3 ms 10844 KB Output is correct
4 Correct 2 ms 10844 KB Output is correct
5 Correct 2 ms 10844 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 3 ms 10844 KB Output is correct
8 Correct 2 ms 11096 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 20316 KB Output is correct
2 Correct 42 ms 20048 KB Output is correct
3 Correct 228 ms 95508 KB Output is correct
4 Correct 75 ms 27252 KB Output is correct
5 Correct 60 ms 27312 KB Output is correct
6 Correct 146 ms 71084 KB Output is correct
7 Correct 292 ms 99888 KB Output is correct
8 Correct 249 ms 100304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 3 ms 10844 KB Output is correct
4 Correct 2 ms 10844 KB Output is correct
5 Correct 2 ms 10844 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 3 ms 10844 KB Output is correct
8 Correct 2 ms 11096 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
11 Correct 51 ms 20316 KB Output is correct
12 Correct 42 ms 20048 KB Output is correct
13 Correct 228 ms 95508 KB Output is correct
14 Correct 75 ms 27252 KB Output is correct
15 Correct 60 ms 27312 KB Output is correct
16 Correct 146 ms 71084 KB Output is correct
17 Correct 292 ms 99888 KB Output is correct
18 Correct 249 ms 100304 KB Output is correct
19 Correct 65 ms 23148 KB Output is correct
20 Correct 50 ms 22568 KB Output is correct
21 Correct 227 ms 99908 KB Output is correct
22 Correct 72 ms 30800 KB Output is correct
23 Correct 81 ms 30996 KB Output is correct
24 Correct 204 ms 75176 KB Output is correct
25 Correct 234 ms 99924 KB Output is correct
26 Correct 274 ms 100692 KB Output is correct
27 Correct 52 ms 22352 KB Output is correct
28 Correct 76 ms 24452 KB Output is correct
29 Correct 468 ms 100176 KB Output is correct
30 Correct 240 ms 62652 KB Output is correct
31 Correct 259 ms 62912 KB Output is correct
32 Correct 385 ms 99952 KB Output is correct
33 Correct 2 ms 10844 KB Output is correct
34 Correct 3 ms 10972 KB Output is correct
35 Correct 2 ms 10844 KB Output is correct
36 Correct 2 ms 10844 KB Output is correct
37 Correct 2 ms 10844 KB Output is correct
38 Correct 2 ms 10944 KB Output is correct
39 Correct 2 ms 10844 KB Output is correct
40 Correct 2 ms 10944 KB Output is correct
41 Correct 2 ms 10840 KB Output is correct
42 Correct 2 ms 10844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 30 ms 13120 KB Output is correct
3 Correct 16 ms 13916 KB Output is correct
4 Correct 69 ms 42640 KB Output is correct
5 Correct 49 ms 42948 KB Output is correct
6 Correct 153 ms 42644 KB Output is correct
7 Correct 21 ms 13988 KB Output is correct
8 Correct 109 ms 42612 KB Output is correct
9 Correct 81 ms 42948 KB Output is correct
10 Correct 101 ms 42704 KB Output is correct
11 Correct 87 ms 29128 KB Output is correct
12 Correct 79 ms 35916 KB Output is correct
13 Correct 70 ms 29300 KB Output is correct
14 Correct 146 ms 42832 KB Output is correct
15 Correct 123 ms 42580 KB Output is correct
16 Correct 3 ms 10840 KB Output is correct
17 Correct 2 ms 10844 KB Output is correct
18 Correct 2 ms 10844 KB Output is correct
19 Correct 2 ms 10844 KB Output is correct
20 Correct 2 ms 10844 KB Output is correct
21 Correct 2 ms 10844 KB Output is correct
22 Correct 3 ms 10948 KB Output is correct
23 Correct 2 ms 10844 KB Output is correct
24 Correct 3 ms 10844 KB Output is correct
25 Correct 2 ms 10844 KB Output is correct