Submission #218683

#TimeUsernameProblemLanguageResultExecution timeMemory
218683EntityIT한자 끝말잇기 (JOI14_kanji)C++14
100 / 100
207 ms17748 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...