結果
問題 | No.1545 [Cherry 2nd Tune N] Anthem |
ユーザー | kakel-san |
提出日時 | 2024-02-25 22:18:31 |
言語 | C# (.NET 8.0.203) |
結果 |
AC
|
実行時間 | 2,229 ms / 3,000 ms |
コード長 | 4,937 bytes |
コンパイル時間 | 16,663 ms |
コンパイル使用メモリ | 169,176 KB |
実行使用メモリ | 461,660 KB |
最終ジャッジ日時 | 2024-09-29 11:23:28 |
合計ジャッジ時間 | 48,707 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 66 ms
31,488 KB |
testcase_01 | AC | 63 ms
30,848 KB |
testcase_02 | AC | 67 ms
31,616 KB |
testcase_03 | AC | 66 ms
31,488 KB |
testcase_04 | AC | 584 ms
117,784 KB |
testcase_05 | AC | 2,229 ms
252,412 KB |
testcase_06 | AC | 589 ms
106,620 KB |
testcase_07 | AC | 469 ms
106,656 KB |
testcase_08 | AC | 1,621 ms
180,992 KB |
testcase_09 | AC | 331 ms
74,320 KB |
testcase_10 | AC | 212 ms
69,276 KB |
testcase_11 | AC | 1,038 ms
136,672 KB |
testcase_12 | AC | 1,770 ms
210,568 KB |
testcase_13 | AC | 348 ms
81,184 KB |
testcase_14 | AC | 683 ms
127,852 KB |
testcase_15 | AC | 124 ms
48,896 KB |
testcase_16 | AC | 1,030 ms
168,276 KB |
testcase_17 | AC | 193 ms
61,032 KB |
testcase_18 | AC | 519 ms
85,096 KB |
testcase_19 | AC | 651 ms
112,636 KB |
testcase_20 | AC | 291 ms
74,756 KB |
testcase_21 | AC | 1,201 ms
193,660 KB |
testcase_22 | AC | 579 ms
114,980 KB |
testcase_23 | AC | 422 ms
72,384 KB |
testcase_24 | AC | 111 ms
48,768 KB |
testcase_25 | AC | 126 ms
55,040 KB |
testcase_26 | AC | 68 ms
31,872 KB |
testcase_27 | AC | 105 ms
40,064 KB |
testcase_28 | AC | 142 ms
60,244 KB |
testcase_29 | AC | 131 ms
60,204 KB |
testcase_30 | AC | 116 ms
49,536 KB |
testcase_31 | AC | 128 ms
51,840 KB |
testcase_32 | AC | 100 ms
41,088 KB |
testcase_33 | AC | 149 ms
60,296 KB |
testcase_34 | AC | 133 ms
54,784 KB |
testcase_35 | AC | 265 ms
95,312 KB |
testcase_36 | AC | 227 ms
95,416 KB |
testcase_37 | AC | 89 ms
36,480 KB |
testcase_38 | AC | 147 ms
60,280 KB |
testcase_39 | AC | 94 ms
37,632 KB |
testcase_40 | AC | 103 ms
44,288 KB |
testcase_41 | AC | 86 ms
34,688 KB |
testcase_42 | AC | 120 ms
49,024 KB |
testcase_43 | AC | 126 ms
54,656 KB |
testcase_44 | AC | 89 ms
36,096 KB |
testcase_45 | AC | 92 ms
42,856 KB |
testcase_46 | AC | 126 ms
48,128 KB |
testcase_47 | AC | 173 ms
62,476 KB |
testcase_48 | AC | 257 ms
94,252 KB |
testcase_49 | AC | 286 ms
86,412 KB |
testcase_50 | AC | 467 ms
127,532 KB |
testcase_51 | AC | 94 ms
37,888 KB |
testcase_52 | AC | 686 ms
169,408 KB |
testcase_53 | AC | 208 ms
78,480 KB |
testcase_54 | AC | 98 ms
40,320 KB |
testcase_55 | AC | 479 ms
137,348 KB |
testcase_56 | AC | 88 ms
36,736 KB |
testcase_57 | AC | 420 ms
109,588 KB |
testcase_58 | AC | 260 ms
94,712 KB |
testcase_59 | AC | 106 ms
40,704 KB |
testcase_60 | AC | 102 ms
45,184 KB |
testcase_61 | AC | 166 ms
61,264 KB |
testcase_62 | AC | 310 ms
96,944 KB |
testcase_63 | AC | 181 ms
64,396 KB |
testcase_64 | AC | 1,664 ms
243,488 KB |
testcase_65 | AC | 108 ms
39,808 KB |
testcase_66 | AC | 1,143 ms
461,660 KB |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (99 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, s, t, k) = (c[0], c[1], c[2], c[3]); var x = NList; var m = NN; var map = NArr(m); var tree = new List<(int to, long len)>[n * k]; var revtree = new List<(int to, long len)>[n * k]; for (var i = 0; i < tree.Length; ++i) { tree[i] = new List<(int to, long len)>(); revtree[i] = new List<(int to, long len)>(); } foreach (var edge in map) { var a = edge[0] - 1; var b = edge[1] - 1; for (var i = 0; i + 1 < k; ++i) { tree[i * n + a].Add(((i + 1) * n + b, x[b] + edge[2])); revtree[(i + 1) * n + b].Add((i * n + a, x[b] + edge[2])); } tree[(k - 1) * n + a].Add(((k - 1) * n + b, x[b] + edge[2])); revtree[(k - 1) * n + b].Add(((k - 1) * n + a, x[b] + edge[2])); } var INF = long.MaxValue / 2; var len = Enumerable.Repeat(INF, n * k).ToArray(); len[s - 1] = x[s - 1]; var q = new PriorityQueue<Pair>(n, false); q.Enqueue(new Pair(s - 1, x[s - 1])); while (q.Count > 0) { var cur = q.Dequeue(); if (len[cur.Pos] != cur.Val) continue; foreach (var next in tree[cur.Pos]) { if (len[next.to] <= cur.Val + next.len) continue; len[next.to] = cur.Val + next.len; q.Enqueue(new Pair(next.to, len[next.to])); } } if (len[(k - 1) * n + t - 1] == INF) { WriteLine("Impossible"); } else { WriteLine("Possible"); var cur = (k - 1) * n + t - 1; var ans = new List<int>(); while (cur != s - 1) { ans.Add(cur % n + 1); foreach (var next in revtree[cur]) { if (len[next.to] == len[cur] - next.len) { cur = next.to; break; } } } ans.Add(s); ans.Reverse(); WriteLine(len[(k - 1) * n + t - 1]); WriteLine(ans.Count); WriteLine(string.Join(" ", ans)); } } class Pair : IComparable<Pair> { public int Pos; public long Val; public Pair(int pos, long val) { Pos = pos; Val = val; } public int CompareTo(Pair b) { return Val.CompareTo(b.Val); } } class PriorityQueue<T> where T : IComparable<T> { public T[] List; public int Count; bool IsTopMax; public PriorityQueue(int count, bool isTopMax) { IsTopMax = isTopMax; List = new T[Math.Max(128, count)]; } public void Enqueue(T value) { if (Count == List.Length) { var newlist = new T[List.Length * 2]; for (var i = 0; i < List.Length; ++i) newlist[i] = List[i]; List = newlist; } var pos = Count; List[pos] = value; ++Count; while (pos > 0) { var parent = (pos - 1) / 2; if (Calc(List[parent], List[pos], true)) break; Swap(parent, pos); pos = parent; } } public T Dequeue() { --Count; Swap(0, Count); var pos = 0; while (true) { var child = pos * 2 + 1; if (child >= Count) break; if (child + 1 < Count && Calc(List[child + 1], List[child], false)) ++child; if (Calc(List[pos], List[child], true)) break; Swap(pos, child); pos = child; } return List[Count]; } bool Calc(T a, T b, bool equalVal) { var ret = a.CompareTo(b); if (ret == 0 && equalVal) return true; return IsTopMax ? ret > 0 : ret < 0; } void Swap(int a, int b) { var tmp = List[a]; List[a] = List[b]; List[b] = tmp; } } }