結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー tarattata1tarattata1
提出日時 2021-06-11 22:42:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 394 ms / 3,000 ms
コード長 3,068 bytes
コンパイル時間 1,023 ms
コンパイル使用メモリ 104,600 KB
実行使用メモリ 136,516 KB
最終ジャッジ日時 2023-08-21 13:26:24
合計ジャッジ時間 16,164 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 121 ms
48,156 KB
testcase_05 AC 394 ms
93,120 KB
testcase_06 AC 137 ms
37,924 KB
testcase_07 AC 126 ms
37,528 KB
testcase_08 AC 280 ms
40,624 KB
testcase_09 AC 67 ms
11,828 KB
testcase_10 AC 54 ms
12,696 KB
testcase_11 AC 193 ms
50,448 KB
testcase_12 AC 309 ms
80,184 KB
testcase_13 AC 84 ms
24,244 KB
testcase_14 AC 126 ms
51,752 KB
testcase_15 AC 20 ms
7,580 KB
testcase_16 AC 172 ms
72,264 KB
testcase_17 AC 29 ms
4,808 KB
testcase_18 AC 158 ms
17,504 KB
testcase_19 AC 153 ms
34,336 KB
testcase_20 AC 51 ms
11,444 KB
testcase_21 AC 207 ms
89,028 KB
testcase_22 AC 128 ms
42,172 KB
testcase_23 AC 109 ms
12,132 KB
testcase_24 AC 8 ms
5,540 KB
testcase_25 AC 11 ms
6,508 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 9 ms
4,952 KB
testcase_28 AC 13 ms
7,460 KB
testcase_29 AC 11 ms
6,840 KB
testcase_30 AC 9 ms
5,608 KB
testcase_31 AC 14 ms
6,332 KB
testcase_32 AC 6 ms
4,832 KB
testcase_33 AC 14 ms
7,388 KB
testcase_34 AC 13 ms
6,480 KB
testcase_35 AC 36 ms
15,600 KB
testcase_36 AC 25 ms
12,284 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 14 ms
7,520 KB
testcase_39 AC 5 ms
4,376 KB
testcase_40 AC 7 ms
5,128 KB
testcase_41 AC 3 ms
4,380 KB
testcase_42 AC 11 ms
5,992 KB
testcase_43 AC 11 ms
6,376 KB
testcase_44 AC 5 ms
4,948 KB
testcase_45 AC 14 ms
13,320 KB
testcase_46 AC 18 ms
9,408 KB
testcase_47 AC 32 ms
15,320 KB
testcase_48 AC 55 ms
36,884 KB
testcase_49 AC 55 ms
22,768 KB
testcase_50 AC 126 ms
40,672 KB
testcase_51 AC 6 ms
4,556 KB
testcase_52 AC 138 ms
44,852 KB
testcase_53 AC 47 ms
21,992 KB
testcase_54 AC 8 ms
5,420 KB
testcase_55 AC 105 ms
36,736 KB
testcase_56 AC 6 ms
5,168 KB
testcase_57 AC 93 ms
28,356 KB
testcase_58 AC 52 ms
22,988 KB
testcase_59 AC 11 ms
6,764 KB
testcase_60 AC 14 ms
10,640 KB
testcase_61 AC 22 ms
10,224 KB
testcase_62 AC 69 ms
23,032 KB
testcase_63 AC 33 ms
12,328 KB
testcase_64 AC 296 ms
82,028 KB
testcase_65 AC 11 ms
5,944 KB
testcase_66 AC 251 ms
136,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <ctime>
#include <bitset>
#pragma warning(disable:4996) 

//#define ATCODER
#ifdef ATCODER
#include <atcoder/all>
#endif

typedef long long ll;
typedef unsigned long long ull;
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;

using namespace std;
#ifdef ATCODER
using namespace atcoder;
#endif

vector<int> pre;

typedef pair<ll, int> P;
vector<ll> dijkstra(int s, const vector<vector<pair<int, int> > >& G) {
    priority_queue< P, vector<P>, greater<P> > que;
    vector<ll> d(G.size(), LINF);
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        int curr = que.top().second;
        ll  dcurr = que.top().first;
        que.pop();
        if (d[curr] < dcurr) continue;
        int i;
        for (i = 0; i < (int)G[curr].size(); i++) {
            int next = G[curr][i].first;
            ll  dist = G[curr][i].second;
            if (d[next] > d[curr] + dist) {
                d[next] = d[curr] + dist;
                que.push(P(d[next], next));
                pre[next] = curr;
            }
        }
    }
    return d;
}

void solve()
{
    int n, S, T, K;
    scanf("%d%d%d%d", &n, &S, &T, &K); S--; T--;
    int num = n * K * 2;
    vector<vector<pair<int, int>>> g(num); 
    pre.resize(num);
#define POS(i,j,k) (((i)*(K)+(j))*2+(k))
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        for (int j = 0; j < K; j++) {
            g[POS(i, j, 0)].push_back(make_pair(POS(i, j, 1), x));
        }            
    }
    
    int m;
    scanf("%d", &m);
    for (int i = 0; i < m; i++) {
        int a, b, y;
        scanf("%d%d%d", &a, &b, &y); a--; b--;
        for (int j = 0; j < K; j++) {
            g[POS(a, j, 1)].push_back(make_pair(POS(b, min(j+1,K-1), 0), y));
        }
    }
    
    vector<ll> dist = dijkstra(POS(S, 0, 0), g);

    if (dist[POS(T, K-1, 1)] == LINF) {
        printf("Impossible\n");
    }
    else {
        printf("Possible\n%lld\n", dist[POS(T, K-1, 1)]);
        int start = POS(S, 0, 0);
        int curr = POS(T, K - 1, 1);
        vector<int> v;
        while (curr != start) {
            if (curr % 2) v.push_back(curr/2/K);
            curr = pre[curr];
        }
        printf("%d\n", (int)v.size());
        reverse(v.begin(), v.end());
        for (int i = 0; i < (int)v.size(); i++) {
            printf("%d", v[i] + 1);
            if (i < (int)v.size() - 1) printf(" ");
            else printf("\n");
        }
    }

    return;
}

int main()
{
#if 1
    solve();
#else
    int T, t;
    scanf("%d", &T);
    for (t = 0; t < T; t++) {
        //printf("Case #%d: ", t + 1);
        solve();
    }
#endif
    return 0;
}
0