답안 #940270

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940270 2024-03-07T07:21:35 Z Whisper Paths (BOI18_paths) C++17
100 / 100
283 ms 100540 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int long long
#define FOR(i, a, b) for ( int i = a ; i <= b ; i++ )
#define FORD(i, a, b) for (int i = b; i >= a; i --)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPD(i, n) for (int i = n - 1; i >= 0; --i)
#define Lg(x) 31 - __builtin_clz(x)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)

constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int MAX = 3e5 + 5;
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void setupIO(){
    #define name "Whisper"
    //Phu Trong from Nguyen Tat Thanh High School for gifted student
    srand(time(NULL));
    cin.tie(nullptr)->sync_with_stdio(false); cout.tie(nullptr);
    //freopen(name".inp", "r", stdin);
    //freopen(name".out", "w", stdout);
    cout << fixed << setprecision(10);
}

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
int numNode, numEdge, numColor;
vector<int> G[MAX];
int C[MAX];

int dp[MAX][MASK(5)];
int F(int node, int msk){
    int &ret = dp[node][msk];
    if (~ret) return ret;
    ret = 1;
    for (int &v : G[node]){
        if (!BIT(msk, C[v])) ret += F(v, msk | MASK(C[v]));
    }
    return ret;
}
void Whisper(){
    cin >> numNode >> numEdge >> numColor;
    for (int i = 1; i <= numNode; ++i){
        cin >> C[i];
        --C[i];
    }
    for (int i = 1; i <= numEdge; ++i){
        int u, v; cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    int ans = 0;
    memset(dp, -1, sizeof dp);
    for (int u = 1; u <= numNode; ++u){
        ans += F(u, MASK(C[u]));
    }
    cout << ans - numNode;
}


signed main(){
    setupIO();
    int Test = 1;
//    cin >> Test;
    for ( int i = 1 ; i <= Test ; i++ ){
        Whisper();
        if (i < Test) cout << '\n';
    }
}


# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 84816 KB Output is correct
2 Correct 13 ms 84940 KB Output is correct
3 Correct 13 ms 84824 KB Output is correct
4 Correct 13 ms 84828 KB Output is correct
5 Correct 13 ms 84828 KB Output is correct
6 Correct 12 ms 84924 KB Output is correct
7 Correct 13 ms 84824 KB Output is correct
8 Correct 13 ms 84828 KB Output is correct
9 Correct 12 ms 84980 KB Output is correct
10 Correct 12 ms 84828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 94800 KB Output is correct
2 Correct 65 ms 94324 KB Output is correct
3 Correct 209 ms 99996 KB Output is correct
4 Correct 88 ms 96336 KB Output is correct
5 Correct 73 ms 96340 KB Output is correct
6 Correct 168 ms 97808 KB Output is correct
7 Correct 214 ms 99852 KB Output is correct
8 Correct 200 ms 100540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 84816 KB Output is correct
2 Correct 13 ms 84940 KB Output is correct
3 Correct 13 ms 84824 KB Output is correct
4 Correct 13 ms 84828 KB Output is correct
5 Correct 13 ms 84828 KB Output is correct
6 Correct 12 ms 84924 KB Output is correct
7 Correct 13 ms 84824 KB Output is correct
8 Correct 13 ms 84828 KB Output is correct
9 Correct 12 ms 84980 KB Output is correct
10 Correct 12 ms 84828 KB Output is correct
11 Correct 65 ms 94800 KB Output is correct
12 Correct 65 ms 94324 KB Output is correct
13 Correct 209 ms 99996 KB Output is correct
14 Correct 88 ms 96336 KB Output is correct
15 Correct 73 ms 96340 KB Output is correct
16 Correct 168 ms 97808 KB Output is correct
17 Correct 214 ms 99852 KB Output is correct
18 Correct 200 ms 100540 KB Output is correct
19 Correct 64 ms 94808 KB Output is correct
20 Correct 53 ms 94288 KB Output is correct
21 Correct 241 ms 99924 KB Output is correct
22 Correct 80 ms 96408 KB Output is correct
23 Correct 94 ms 96388 KB Output is correct
24 Correct 163 ms 97920 KB Output is correct
25 Correct 196 ms 99920 KB Output is correct
26 Correct 183 ms 100324 KB Output is correct
27 Correct 64 ms 94316 KB Output is correct
28 Correct 82 ms 96212 KB Output is correct
29 Correct 283 ms 100176 KB Output is correct
30 Correct 187 ms 97604 KB Output is correct
31 Correct 199 ms 97732 KB Output is correct
32 Correct 245 ms 99924 KB Output is correct
33 Correct 12 ms 84824 KB Output is correct
34 Correct 13 ms 85008 KB Output is correct
35 Correct 11 ms 84936 KB Output is correct
36 Correct 12 ms 84828 KB Output is correct
37 Correct 12 ms 84824 KB Output is correct
38 Correct 13 ms 84936 KB Output is correct
39 Correct 12 ms 84824 KB Output is correct
40 Correct 12 ms 84824 KB Output is correct
41 Correct 11 ms 84940 KB Output is correct
42 Correct 12 ms 84980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 84828 KB Output is correct
2 Correct 37 ms 87900 KB Output is correct
3 Correct 26 ms 87892 KB Output is correct
4 Correct 55 ms 89680 KB Output is correct
5 Correct 46 ms 90060 KB Output is correct
6 Correct 71 ms 89852 KB Output is correct
7 Correct 29 ms 87888 KB Output is correct
8 Correct 67 ms 89852 KB Output is correct
9 Correct 59 ms 90076 KB Output is correct
10 Correct 58 ms 89796 KB Output is correct
11 Correct 62 ms 88524 KB Output is correct
12 Correct 51 ms 89404 KB Output is correct
13 Correct 63 ms 88644 KB Output is correct
14 Correct 72 ms 89844 KB Output is correct
15 Correct 65 ms 89948 KB Output is correct
16 Correct 12 ms 84828 KB Output is correct
17 Correct 12 ms 84956 KB Output is correct
18 Correct 12 ms 84828 KB Output is correct
19 Correct 11 ms 84936 KB Output is correct
20 Correct 13 ms 84928 KB Output is correct
21 Correct 12 ms 84828 KB Output is correct
22 Correct 12 ms 84880 KB Output is correct
23 Correct 12 ms 84824 KB Output is correct
24 Correct 12 ms 84928 KB Output is correct
25 Correct 12 ms 84828 KB Output is correct