Submission #218587

# Submission time Handle Problem Language Result Execution time Memory
218587 2020-04-02T10:20:05 Z EntityIT 한자 끝말잇기 (JOI14_kanji) C++14
91 / 100
200 ms 17744 KB
#include<bits/stdc++.h>
using namespace std;

#include "Annalib.h"

#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;

template<class T>
inline bool asMn(T &a, const T &b) { return a > b ? a = b, true : false; }
template<class T>
inline bool asMx(T &a, const T &b) { return a < b ? a = b, true : false; }

const LL infLL = 4e18;

void Anna(int N, int M, int A[], int B[], LL C[], int Q, int S[], int T[], int K, int U[]) {
    vector<vector<LL> > d(N, vector<LL>(N, infLL) );
    for (int u = 0; u < N; ++u) d[u][u] = 0;
    for (int i = 0; i < M; ++i) d[ A[i] ][ B[i] ] = C[i];
    for (int i = 0; i < K; ++i) d[ A[ U[i] ] ][ B[ U[i] ] ] = infLL;
    for (int w = 0; w < N; ++w) {
        for (int u = 0; u < N; ++u) {
            for (int v = 0; v < N; ++v) {
                asMn(d[u][v], d[u][w] + d[w][v]);
            }
        }
    }

    vector<int> group(Q, -1);
    vector<LL> ans(Q);
    for (int i = 0; i < Q; ++i) ans[i] = d[ S[i] ][ T[i] ];

    vector<int> tap;
    for (int i = 0; i < K; ++i) {
        vector<int> cnt(i + 1);
        for (int j = 0; j <= i; ++j) cnt[j] = count(all(group), j - 1);
        vector<int> cnt2(i + 1);
        for (int j = 0; j < Q; ++j) if (asMn(ans[j], C[ U[i] ] + d[ S[j] ][ A[ U[i] ] ] + d[ B[ U[i] ] ][ T[j] ]) ) {
            ++cnt2[ group[j] + 1 ];
            group[j] = i;
        }

        for (int j = 0; j <= i; ++j) if (cnt[j]) {
            for (int k = __lg(cnt[j]); ~k; --k) tap.emplace_back(cnt2[j] >> k & 1);
        }
    }

    for (const auto &i : tap) Tap(i);
}
#include<bits/stdc++.h>
using namespace std;

#include "Brunolib.h"

#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;

template<class T>
inline bool asMn(T &a, const T &b) { return a > b ? a = b, true : false; }
template<class T>
inline bool asMx(T &a, const T &b) { return a < b ? a = b, true : false; }

const LL infLL = 4e18;

void Bruno(int N, int M, int A[], int B[], long long C[], int Q, int S[], int T[], int K, int U[], int L, int X[]) {
    vector<vector<LL> > d(N, vector<LL>(N, infLL) ),
                        trace(N, vector<LL>(N, -1) );
    for (int u = 0; u < N; ++u) d[u][u] = 0;
    for (int i = 0; i < M; ++i) {
        d[ A[i] ][ B[i] ] = C[i];
        trace[ A[i] ][ B[i] ] = i;
    }
    for (int i = 0; i < K; ++i) {
        d[ A[ U[i] ] ][ B[ U[i] ] ] = infLL;
        trace[ A[ U[i] ] ][ B[ U[i] ] ] = -1;
    }
    for (int w = 0; w < N; ++w) {
        for (int u = 0; u < N; ++u) {
            for (int v = 0; v < N; ++v) {
                if (asMn(d[u][v], d[u][w] + d[w][v]) ) trace[u][v] = trace[u][w];
            }
        }
    }

    auto get = [&](int iQ, int i, int j) {
        return d[ S[iQ] ][ A[ U[j] ] ] + d[ B[ U[j] ] ][ T[iQ] ]
             - (~i ? d[ S[iQ] ][ A[ U[i] ] ] + d[ B[ U[i] ] ][ T[iQ] ] : d[ S[iQ] ][ T[iQ] ]);
    };
    vector<int> group(Q, -1);

    for (int i = 0, iX = 0; i < K; ++i) {
        vector<vector<int> > iQ(i + 1);
        for (int j = 0; j < Q; ++j) iQ[ group[j] + 1 ].emplace_back(j);
        for (auto &j : iQ) {
            sort(all(j), [&](const int &a, const int &b) {
                return get(a, group[a], i) < get(b, group[b], i);
            });
        }
        
        for (int j = 0; j <= i; ++j) {
            int cnt = count(all(group), j - 1);
            if (!cnt) continue ;

            int tmp = 0;
            for (int k = __lg(cnt); ~k; --k) if (X[iX++]) tmp |= 1 << k;

            for (int k = 0; k < tmp; ++k) group[ iQ[j][k] ] = i;
        }
    }

    function<void(int, int)> answer = [&](int u, int v) {
        if (u == v) return ;
        Answer(trace[u][v]);
        answer(B[ trace[u][v] ], v);
    };
    for (int i = 0; i < Q; ++i) {
        if (~group[i]) {
            answer(S[i], A[ U[ group[i] ] ]);
            Answer(U[ group[i] ]);
            answer(B[ U[ group[i] ] ], T[i]);
        }
        else answer(S[i], T[i]);
        Answer(-1);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 65 ms 6684 KB Output is correct - L = 27
2 Correct 64 ms 6784 KB Output is correct - L = 27
3 Correct 63 ms 6684 KB Output is correct - L = 23
4 Correct 63 ms 6572 KB Output is correct - L = 29
5 Correct 62 ms 6684 KB Output is correct - L = 26
6 Correct 62 ms 6700 KB Output is correct - L = 29
7 Correct 62 ms 6564 KB Output is correct - L = 33
8 Correct 74 ms 7184 KB Output is correct - L = 20
9 Correct 77 ms 6772 KB Output is correct - L = 20
10 Correct 80 ms 7016 KB Output is correct - L = 20
11 Correct 72 ms 6708 KB Output is correct - L = 5
12 Correct 191 ms 17404 KB Output is correct - L = 20
13 Correct 62 ms 6704 KB Output is correct - L = 29
14 Correct 64 ms 6596 KB Output is correct - L = 1
# Verdict Execution time Memory Grader output
1 Correct 62 ms 7044 KB Output is correct - L = 70
2 Correct 63 ms 6716 KB Output is correct - L = 68
3 Correct 64 ms 6952 KB Output is correct - L = 46
4 Correct 62 ms 6932 KB Output is correct - L = 48
5 Correct 64 ms 6664 KB Output is correct - L = 65
6 Correct 65 ms 6952 KB Output is correct - L = 65
7 Correct 63 ms 6936 KB Output is correct - L = 34
8 Correct 77 ms 7164 KB Output is correct - L = 34
9 Correct 62 ms 7156 KB Output is correct - L = 67
10 Correct 62 ms 7068 KB Output is correct - L = 67
11 Correct 63 ms 6988 KB Output is correct - L = 67
12 Correct 67 ms 7116 KB Output is correct - L = 30
13 Correct 200 ms 17716 KB Output is correct - L = 30
14 Correct 65 ms 6948 KB Output is correct - L = 65
15 Correct 64 ms 7108 KB Output is correct - L = 40
16 Correct 75 ms 7164 KB Output is correct - L = 35
17 Correct 82 ms 7172 KB Output is correct - L = 39
18 Correct 92 ms 7576 KB Output is correct - L = 45
19 Correct 65 ms 6960 KB Output is correct - L = 39
20 Correct 77 ms 8048 KB Output is correct - L = 30
21 Correct 91 ms 8040 KB Output is correct - L = 30
22 Correct 61 ms 7048 KB Output is correct - L = 69
23 Correct 60 ms 7052 KB Output is correct - L = 68
24 Correct 61 ms 7048 KB Output is correct - L = 69
# Verdict Execution time Memory Grader output
1 Correct 63 ms 6936 KB Output is correct - L = 70
2 Correct 66 ms 6944 KB Output is correct - L = 68
3 Correct 62 ms 7076 KB Output is correct - L = 46
4 Correct 62 ms 6708 KB Output is correct - L = 48
5 Correct 64 ms 6680 KB Output is correct - L = 65
6 Correct 64 ms 6952 KB Output is correct - L = 65
7 Correct 63 ms 6936 KB Output is correct - L = 34
8 Correct 67 ms 7300 KB Output is correct - L = 34
9 Correct 62 ms 7052 KB Output is correct - L = 67
10 Correct 64 ms 7064 KB Output is correct - L = 67
11 Correct 62 ms 7056 KB Output is correct - L = 67
12 Correct 66 ms 7052 KB Output is correct - L = 30
13 Correct 198 ms 17532 KB Output is correct - L = 30
14 Correct 65 ms 6948 KB Output is correct - L = 65
15 Correct 66 ms 7040 KB Output is correct - L = 40
16 Correct 77 ms 7064 KB Output is correct - L = 35
17 Correct 86 ms 7324 KB Output is correct - L = 39
18 Correct 91 ms 7896 KB Output is correct - L = 45
19 Correct 65 ms 6700 KB Output is correct - L = 39
20 Correct 75 ms 8052 KB Output is correct - L = 30
21 Correct 91 ms 8040 KB Output is correct - L = 30
22 Correct 61 ms 7056 KB Output is correct - L = 69
23 Correct 62 ms 7064 KB Output is correct - L = 68
24 Correct 63 ms 7048 KB Output is correct - L = 69
# Verdict Execution time Memory Grader output
1 Correct 61 ms 6928 KB Output is correct - L = 70
2 Correct 62 ms 6856 KB Output is correct - L = 68
3 Correct 63 ms 6952 KB Output is correct - L = 46
4 Correct 65 ms 6972 KB Output is correct - L = 48
5 Correct 68 ms 6684 KB Output is correct - L = 65
6 Correct 66 ms 7016 KB Output is correct - L = 65
7 Correct 65 ms 6932 KB Output is correct - L = 34
8 Correct 64 ms 7172 KB Output is correct - L = 34
9 Correct 62 ms 6996 KB Output is correct - L = 67
10 Correct 61 ms 7056 KB Output is correct - L = 67
11 Correct 62 ms 6988 KB Output is correct - L = 67
12 Correct 66 ms 7176 KB Output is correct - L = 30
13 Correct 194 ms 17736 KB Output is correct - L = 30
14 Correct 65 ms 6844 KB Output is correct - L = 65
15 Correct 63 ms 6936 KB Output is correct - L = 40
16 Correct 79 ms 7160 KB Output is correct - L = 35
17 Correct 82 ms 7180 KB Output is correct - L = 39
18 Correct 91 ms 7704 KB Output is correct - L = 45
19 Correct 70 ms 6800 KB Output is correct - L = 39
20 Correct 76 ms 8088 KB Output is correct - L = 30
21 Correct 90 ms 8040 KB Output is correct - L = 30
22 Correct 61 ms 7064 KB Output is correct - L = 69
23 Correct 61 ms 7068 KB Output is correct - L = 68
24 Correct 62 ms 6980 KB Output is correct - L = 69
# Verdict Execution time Memory Grader output
1 Correct 62 ms 6908 KB Output is partially correct - L = 70
2 Correct 63 ms 6868 KB Output is partially correct - L = 68
3 Correct 63 ms 7112 KB Output is correct - L = 46
4 Correct 62 ms 7084 KB Output is correct - L = 48
5 Correct 65 ms 6700 KB Output is partially correct - L = 65
6 Correct 64 ms 6956 KB Output is partially correct - L = 65
7 Correct 64 ms 7044 KB Output is correct - L = 34
8 Correct 65 ms 6972 KB Output is correct - L = 34
9 Correct 61 ms 7060 KB Output is partially correct - L = 67
10 Correct 62 ms 7060 KB Output is partially correct - L = 67
11 Correct 63 ms 7048 KB Output is partially correct - L = 67
12 Correct 65 ms 7064 KB Output is correct - L = 30
13 Correct 195 ms 17744 KB Output is correct - L = 30
14 Correct 64 ms 6944 KB Output is partially correct - L = 65
15 Correct 63 ms 7040 KB Output is correct - L = 40
16 Correct 77 ms 7132 KB Output is correct - L = 35
17 Correct 83 ms 7176 KB Output is correct - L = 39
18 Correct 90 ms 7652 KB Output is correct - L = 45
19 Correct 63 ms 6704 KB Output is correct - L = 39
20 Correct 77 ms 8052 KB Output is correct - L = 30
21 Correct 100 ms 8168 KB Output is correct - L = 30
22 Correct 62 ms 7056 KB Output is partially correct - L = 69
23 Correct 62 ms 7032 KB Output is partially correct - L = 68
24 Correct 61 ms 6996 KB Output is partially correct - L = 69