結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー tnakao0123tnakao0123
提出日時 2021-06-12 21:40:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 561 ms / 3,000 ms
コード長 2,404 bytes
コンパイル時間 1,351 ms
コンパイル使用メモリ 114,380 KB
実行使用メモリ 39,232 KB
最終ジャッジ日時 2023-08-22 18:33:49
合計ジャッジ時間 20,570 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,896 KB
testcase_01 AC 3 ms
5,692 KB
testcase_02 AC 4 ms
5,780 KB
testcase_03 AC 3 ms
5,752 KB
testcase_04 AC 38 ms
7,256 KB
testcase_05 AC 121 ms
11,472 KB
testcase_06 AC 64 ms
9,600 KB
testcase_07 AC 86 ms
10,932 KB
testcase_08 AC 345 ms
17,432 KB
testcase_09 AC 65 ms
8,060 KB
testcase_10 AC 47 ms
7,624 KB
testcase_11 AC 55 ms
8,240 KB
testcase_12 AC 84 ms
9,180 KB
testcase_13 AC 31 ms
7,244 KB
testcase_14 AC 32 ms
7,376 KB
testcase_15 AC 14 ms
6,476 KB
testcase_16 AC 43 ms
7,876 KB
testcase_17 AC 40 ms
7,052 KB
testcase_18 AC 106 ms
10,440 KB
testcase_19 AC 62 ms
8,972 KB
testcase_20 AC 64 ms
8,032 KB
testcase_21 AC 59 ms
8,764 KB
testcase_22 AC 67 ms
9,468 KB
testcase_23 AC 86 ms
9,344 KB
testcase_24 AC 15 ms
6,164 KB
testcase_25 AC 28 ms
6,572 KB
testcase_26 AC 4 ms
5,884 KB
testcase_27 AC 19 ms
6,820 KB
testcase_28 AC 36 ms
6,520 KB
testcase_29 AC 24 ms
6,292 KB
testcase_30 AC 25 ms
6,232 KB
testcase_31 AC 33 ms
6,788 KB
testcase_32 AC 13 ms
6,260 KB
testcase_33 AC 41 ms
6,684 KB
testcase_34 AC 33 ms
6,596 KB
testcase_35 AC 117 ms
7,292 KB
testcase_36 AC 84 ms
6,740 KB
testcase_37 AC 8 ms
6,108 KB
testcase_38 AC 43 ms
6,840 KB
testcase_39 AC 10 ms
6,140 KB
testcase_40 AC 16 ms
6,388 KB
testcase_41 AC 6 ms
6,048 KB
testcase_42 AC 24 ms
6,548 KB
testcase_43 AC 31 ms
6,396 KB
testcase_44 AC 11 ms
7,192 KB
testcase_45 AC 3 ms
5,756 KB
testcase_46 AC 33 ms
10,072 KB
testcase_47 AC 81 ms
14,300 KB
testcase_48 AC 91 ms
18,428 KB
testcase_49 AC 176 ms
18,752 KB
testcase_50 AC 434 ms
31,956 KB
testcase_51 AC 9 ms
6,556 KB
testcase_52 AC 561 ms
31,124 KB
testcase_53 AC 138 ms
18,968 KB
testcase_54 AC 17 ms
7,256 KB
testcase_55 AC 306 ms
27,356 KB
testcase_56 AC 12 ms
7,304 KB
testcase_57 AC 239 ms
21,636 KB
testcase_58 AC 149 ms
18,584 KB
testcase_59 AC 22 ms
8,516 KB
testcase_60 AC 21 ms
8,404 KB
testcase_61 AC 52 ms
10,228 KB
testcase_62 AC 228 ms
17,972 KB
testcase_63 AC 94 ms
11,564 KB
testcase_64 AC 498 ms
39,232 KB
testcase_65 AC 13 ms
6,836 KB
testcase_66 AC 143 ms
20,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1545.cc:  No.1545 [Cherry 2nd Tune N] Anthem - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_K = 30000;

/* typedef */

typedef unsigned int ui;
typedef vector<ui> vu;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ui> plu;
typedef vector<pii> vpii;
typedef map<ui,ll> mul;
typedef map<ui,ui> muu;

/* global variables */

int xs[MAX_N];
vpii nbrs[MAX_N];
mul ds;
muu ps;

/* subroutines */

inline ui ab2p(ui a, ui b, int k) { return a * k + b; }
inline void p2ab(ui p, ui &a, ui &b, int k) { a = p / k, b = p % k; }

/* main */

int main() {
  int n, st, gl, k;
  scanf("%d%d%d%d", &n, &st, &gl, &k);
  st--, gl--;

  for (int i = 0; i < n; i++) scanf("%d", xs + i);

  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--;
    nbrs[a].push_back(pii(b, y));
  }

  ui stp = ab2p(st, 0, k), glp = ab2p(gl, k - 1, k);

  ds[stp] = xs[st];

  priority_queue<plu> q;
  q.push(plu(-xs[st], stp));

  while (! q.empty()) {
    plu u = q.top(); q.pop();
    ll ud = -u.first;
    ui up = u.second;
    if (ds[up] != ud) continue;
    if (up == glp) break;

    ui ua, ub;
    p2ab(up, ua, ub, k);

    for (auto vy: nbrs[ua]) {
      ui va = vy.first, vb = min<ui>(ub + 1, k - 1);
      ui vp = ab2p(va, vb, k);
      ll vd = ud + vy.second + xs[va];
      mul::iterator mit = ds.find(vp);
      if (mit == ds.end()) {
	ds[vp] = vd;
	ps[vp] = up;
	q.push(plu(-vd, vp));
      }
      else if (mit->second > vd) {
	mit->second = vd;
	ps[vp] = up;
	q.push(plu(-vd, vp));
      }
    }
  }

  mul::iterator mit = ds.find(glp);
  if (mit == ds.end()) puts("Impossible");
  else {
    vu vs;
    vs.push_back(gl);
    for (muu::iterator mit0 = ps.find(glp); mit0 != ps.end();) {
      vs.push_back(mit0->second / k);
      mit0 = ps.find(mit0->second);
    }

    printf("Possible\n%lld\n%lu\n", mit->second, vs.size());
    for (int i = vs.size() - 1; i >= 0; i--)
      printf("%u%c", vs[i] + 1, (i > 0) ? ' ' : '\n');
  }
  return 0;
}
0