結果
問題 | No.1545 [Cherry 2nd Tune N] Anthem |
ユーザー | firiexp |
提出日時 | 2021-06-11 22:10:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,528 bytes |
コンパイル時間 | 1,000 ms |
コンパイル使用メモリ | 100,196 KB |
最終ジャッジ日時 | 2025-01-22 05:59:00 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In instantiation of ‘class RadixHeap<long long int, int>’: main.cpp:97:24: required from here main.cpp:32:43: error: ‘RadixHeap<K, V>::v’ has incomplete type 32 | array<vector<pair<K, V>>, bit_length> v; | ^ In file included from /usr/include/c++/13/bits/memory_resource.h:47, from /usr/include/c++/13/string:58, from /usr/include/c++/13/bits/locale_classes.h:40, from /usr/include/c++/13/bits/ios_base.h:41, from /usr/include/c++/13/ios:44, from /usr/include/c++/13/ostream:40, from /usr/include/c++/13/iostream:41, from main.cpp:1: /usr/include/c++/13/tuple:2019:45: note: declaration of ‘struct std::array<std::vector<std::pair<long long int, int>, std::allocator<std::pair<long long int, int> > >, 64>’ 2019 | template<typename _Tp, size_t _Nm> struct array; | ^~~~~ main.cpp: In function ‘int main()’: main.cpp:75:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 75 | for (auto &&i : X) scanf("%d", &i); | ~~~~~^~~~~~~~~~ main.cpp:81:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 81 | scanf("%d %d %d", &a, &b, &y); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream> #include <algorithm> #include <map> #include <set> #include <queue> #include <stack> #include <numeric> #include <bitset> #include <cmath> static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208; template <class T, class U> vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); } template<class... Ts, class U> auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class K, class V> class RadixHeap { static constexpr int bit_length = sizeof(K)*8; K last; size_t sz, cnt; array<vector<pair<K, V>>, bit_length> v; static inline int bsr(int x){ return x ? bit_length-__builtin_clz(x) : 0; } static inline int bsr(ll x){ return x ? bit_length-__builtin_clzll(x) : 0; } void pull() { if(cnt < v[0].size()) return;; int i = 1; while(v[i].empty()) i++; last = min_element(v[i].begin(),v[i].end())->first; for (auto &&x : v[i]) v[bsr(x.first ^ last)].push_back(x); v[i].clear(); } public: RadixHeap() : last(0), sz(0), cnt(0) {} void emplace(K x, V val){ sz++; v[bsr(x^last)].emplace_back(x, val); } pair<K, V> top() { pull(); return v[0][cnt]; } void pop() { pull(); sz--; cnt++; } size_t size() const { return sz; } bool empty() const { return !sz; } }; int main() { int n, s, t, k; cin >> n >> s >> t >> k; s--; t--; vector<int> X(n); for (auto &&i : X) scanf("%d", &i); vector<vector<pair<int, int>>> G(n); int m; cin >> m; for (int i = 0; i < m; ++i) { int a, b, y; scanf("%d %d %d", &a, &b, &y); a-- ;b--; G[a].emplace_back(b, X[b]+y); } auto dp = make_v(k+1, n, INF<ll>); auto prv = make_v(k+1, n, pair<int, int>(-1, -1)); dp[1][s] = X[s]; for (int i = 1; i < k; ++i) { for (int j = 0; j < n; ++j) { for (auto [l, v] : G[j]) { if(chmin(dp[i+1][l], dp[i][j]+v)){ prv[i+1][l] = {i, j}; } } } } RadixHeap<ll, int> Q; for (int i = 0; i < n; ++i) { Q.emplace(dp[k][i], i); } while(!Q.empty()){ auto [val, x] = Q.top(); Q.pop(); if(dp[k][x] < val) continue; for (auto [l, v] : G[x]) { if(dp[k][l] > val+v){ dp[k][l] = val+v; Q.emplace(val+v, l); prv[k][l] = {k, x}; } } } if(dp[k][t] == INF<ll>) { puts("Impossible"); }else { puts("Possible"); cout << dp[k][t] << "\n"; ll p = k, q = t; vector<ll> ans; while(prv[p][q].first > 0){ ans.emplace_back(q); tie(p, q) = prv[p][q]; } ans.emplace_back(q); reverse(ans.begin(),ans.end()); cout << ans.size() << "\n"; for (int i = 0; i < ans.size(); ++i) { if(i) printf(" "); printf("%lld", ans[i]+1); } puts(""); } return 0; }