# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
218683 |
2020-04-02T13:58:52 Z |
EntityIT |
한자 끝말잇기 (JOI14_kanji) |
C++14 |
|
207 ms |
17748 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<pair<int, int> > a;
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) a.emplace_back(cnt[j] + 1, cnt2[j]);
}
uint64_t tap = 0;
reverse(all(a) );
for (const auto &i : a) tap *= i.first, tap += i.second;
for (; tap; tap >>= 1) Tap(tap & 1);
}
#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);
uint64_t tap = 0;
for (int i = 0; i < L; ++i) if (X[i]) tap |= 1LL << i;
for (int i = 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);
});
}
vector<int> cnt(i + 1);
for (int j = 0; j <= i; ++j) cnt[j] = (int)count(all(group), j - 1);
vector<int> tmp(i + 1);
for (int j = 0; j <= i; ++j) {
tmp[j] = tap % (cnt[j] + 1);
tap /= cnt[j] + 1;
}
for (int j = 0; j <= i; ++j) {
for (int k = 0; k < tmp[j]; ++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 |
76 ms |
6684 KB |
Output is correct - L = 19 |
2 |
Correct |
64 ms |
6680 KB |
Output is correct - L = 20 |
3 |
Correct |
66 ms |
6956 KB |
Output is correct - L = 4 |
4 |
Correct |
63 ms |
6588 KB |
Output is correct - L = 25 |
5 |
Correct |
67 ms |
6564 KB |
Output is correct - L = 25 |
6 |
Correct |
62 ms |
6576 KB |
Output is correct - L = 22 |
7 |
Correct |
63 ms |
6788 KB |
Output is correct - L = 19 |
8 |
Correct |
78 ms |
6580 KB |
Output is correct - L = 4 |
9 |
Correct |
77 ms |
6788 KB |
Output is correct - L = 7 |
10 |
Correct |
80 ms |
7016 KB |
Output is correct - L = 4 |
11 |
Correct |
64 ms |
6704 KB |
Output is correct - L = 5 |
12 |
Correct |
192 ms |
17488 KB |
Output is correct - L = 0 |
13 |
Correct |
63 ms |
6696 KB |
Output is correct - L = 10 |
14 |
Correct |
65 ms |
6560 KB |
Output is correct - L = 0 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
6904 KB |
Output is correct - L = 62 |
2 |
Correct |
62 ms |
6860 KB |
Output is correct - L = 52 |
3 |
Correct |
62 ms |
6820 KB |
Output is correct - L = 4 |
4 |
Correct |
62 ms |
7040 KB |
Output is correct - L = 34 |
5 |
Correct |
63 ms |
6688 KB |
Output is correct - L = 46 |
6 |
Correct |
65 ms |
6956 KB |
Output is correct - L = 57 |
7 |
Correct |
64 ms |
6828 KB |
Output is correct - L = 1 |
8 |
Correct |
64 ms |
7068 KB |
Output is correct - L = 1 |
9 |
Correct |
61 ms |
7048 KB |
Output is correct - L = 61 |
10 |
Correct |
61 ms |
7044 KB |
Output is correct - L = 61 |
11 |
Correct |
61 ms |
7044 KB |
Output is correct - L = 61 |
12 |
Correct |
67 ms |
7028 KB |
Output is correct - L = 0 |
13 |
Correct |
195 ms |
17748 KB |
Output is correct - L = 0 |
14 |
Correct |
64 ms |
6948 KB |
Output is correct - L = 58 |
15 |
Correct |
63 ms |
6912 KB |
Output is correct - L = 12 |
16 |
Correct |
75 ms |
7028 KB |
Output is correct - L = 22 |
17 |
Correct |
86 ms |
7184 KB |
Output is correct - L = 20 |
18 |
Correct |
90 ms |
7648 KB |
Output is correct - L = 37 |
19 |
Correct |
62 ms |
6572 KB |
Output is correct - L = 36 |
20 |
Correct |
75 ms |
8056 KB |
Output is correct - L = 0 |
21 |
Correct |
89 ms |
8032 KB |
Output is correct - L = 0 |
22 |
Correct |
62 ms |
7120 KB |
Output is correct - L = 60 |
23 |
Correct |
61 ms |
7032 KB |
Output is correct - L = 60 |
24 |
Correct |
62 ms |
7048 KB |
Output is correct - L = 60 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
7028 KB |
Output is correct - L = 62 |
2 |
Correct |
62 ms |
6832 KB |
Output is correct - L = 52 |
3 |
Correct |
62 ms |
6824 KB |
Output is correct - L = 4 |
4 |
Correct |
63 ms |
6932 KB |
Output is correct - L = 34 |
5 |
Correct |
63 ms |
6680 KB |
Output is correct - L = 46 |
6 |
Correct |
65 ms |
6944 KB |
Output is correct - L = 57 |
7 |
Correct |
64 ms |
6932 KB |
Output is correct - L = 1 |
8 |
Correct |
65 ms |
7044 KB |
Output is correct - L = 1 |
9 |
Correct |
60 ms |
6972 KB |
Output is correct - L = 61 |
10 |
Correct |
62 ms |
7040 KB |
Output is correct - L = 61 |
11 |
Correct |
62 ms |
7044 KB |
Output is correct - L = 61 |
12 |
Correct |
65 ms |
6940 KB |
Output is correct - L = 0 |
13 |
Correct |
207 ms |
17704 KB |
Output is correct - L = 0 |
14 |
Correct |
64 ms |
7076 KB |
Output is correct - L = 58 |
15 |
Correct |
63 ms |
6932 KB |
Output is correct - L = 12 |
16 |
Correct |
75 ms |
7020 KB |
Output is correct - L = 22 |
17 |
Correct |
83 ms |
7244 KB |
Output is correct - L = 20 |
18 |
Correct |
88 ms |
7624 KB |
Output is correct - L = 37 |
19 |
Correct |
62 ms |
6696 KB |
Output is correct - L = 36 |
20 |
Correct |
78 ms |
8052 KB |
Output is correct - L = 0 |
21 |
Correct |
89 ms |
8036 KB |
Output is correct - L = 0 |
22 |
Correct |
64 ms |
7060 KB |
Output is correct - L = 60 |
23 |
Correct |
61 ms |
7068 KB |
Output is correct - L = 60 |
24 |
Correct |
61 ms |
7180 KB |
Output is correct - L = 60 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
7024 KB |
Output is correct - L = 62 |
2 |
Correct |
63 ms |
6856 KB |
Output is correct - L = 52 |
3 |
Correct |
63 ms |
6956 KB |
Output is correct - L = 4 |
4 |
Correct |
63 ms |
7032 KB |
Output is correct - L = 34 |
5 |
Correct |
64 ms |
6684 KB |
Output is correct - L = 46 |
6 |
Correct |
64 ms |
6952 KB |
Output is correct - L = 57 |
7 |
Correct |
67 ms |
6700 KB |
Output is correct - L = 1 |
8 |
Correct |
64 ms |
6964 KB |
Output is correct - L = 1 |
9 |
Correct |
61 ms |
7048 KB |
Output is correct - L = 61 |
10 |
Correct |
62 ms |
6844 KB |
Output is correct - L = 61 |
11 |
Correct |
66 ms |
7100 KB |
Output is correct - L = 61 |
12 |
Correct |
64 ms |
6932 KB |
Output is correct - L = 0 |
13 |
Correct |
192 ms |
17744 KB |
Output is correct - L = 0 |
14 |
Correct |
64 ms |
6948 KB |
Output is correct - L = 58 |
15 |
Correct |
66 ms |
6936 KB |
Output is correct - L = 12 |
16 |
Correct |
77 ms |
7068 KB |
Output is correct - L = 22 |
17 |
Correct |
84 ms |
7032 KB |
Output is correct - L = 20 |
18 |
Correct |
94 ms |
7648 KB |
Output is correct - L = 37 |
19 |
Correct |
63 ms |
6688 KB |
Output is correct - L = 36 |
20 |
Correct |
75 ms |
8052 KB |
Output is correct - L = 0 |
21 |
Correct |
90 ms |
7912 KB |
Output is correct - L = 0 |
22 |
Correct |
64 ms |
7056 KB |
Output is correct - L = 60 |
23 |
Correct |
64 ms |
7052 KB |
Output is correct - L = 60 |
24 |
Correct |
61 ms |
7192 KB |
Output is correct - L = 60 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
6820 KB |
Output is correct - L = 62 |
2 |
Correct |
60 ms |
6820 KB |
Output is correct - L = 52 |
3 |
Correct |
62 ms |
6820 KB |
Output is correct - L = 4 |
4 |
Correct |
63 ms |
6928 KB |
Output is correct - L = 34 |
5 |
Correct |
64 ms |
6680 KB |
Output is correct - L = 46 |
6 |
Correct |
66 ms |
6948 KB |
Output is correct - L = 57 |
7 |
Correct |
65 ms |
7064 KB |
Output is correct - L = 1 |
8 |
Correct |
64 ms |
7044 KB |
Output is correct - L = 1 |
9 |
Correct |
61 ms |
7040 KB |
Output is correct - L = 61 |
10 |
Correct |
62 ms |
7188 KB |
Output is correct - L = 61 |
11 |
Correct |
62 ms |
7044 KB |
Output is correct - L = 61 |
12 |
Correct |
66 ms |
7048 KB |
Output is correct - L = 0 |
13 |
Correct |
192 ms |
17740 KB |
Output is correct - L = 0 |
14 |
Correct |
69 ms |
6944 KB |
Output is correct - L = 58 |
15 |
Correct |
65 ms |
6944 KB |
Output is correct - L = 12 |
16 |
Correct |
75 ms |
7068 KB |
Output is correct - L = 22 |
17 |
Correct |
82 ms |
7300 KB |
Output is correct - L = 20 |
18 |
Correct |
91 ms |
7724 KB |
Output is correct - L = 37 |
19 |
Correct |
62 ms |
6576 KB |
Output is correct - L = 36 |
20 |
Correct |
77 ms |
8052 KB |
Output is correct - L = 0 |
21 |
Correct |
89 ms |
7912 KB |
Output is correct - L = 0 |
22 |
Correct |
64 ms |
6972 KB |
Output is correct - L = 60 |
23 |
Correct |
61 ms |
7056 KB |
Output is correct - L = 60 |
24 |
Correct |
61 ms |
7056 KB |
Output is correct - L = 60 |