結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | itt828 |
提出日時 | 2021-04-10 00:29:39 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 1,084 ms / 2,000 ms |
コード長 | 8,441 bytes |
コンパイル時間 | 4,038 ms |
コンパイル使用メモリ | 118,092 KB |
実行使用メモリ | 51,824 KB |
最終ジャッジ日時 | 2024-06-25 13:13:50 |
合計ジャッジ時間 | 22,842 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
25,792 KB |
testcase_01 | AC | 36 ms
25,792 KB |
testcase_02 | AC | 683 ms
48,172 KB |
testcase_03 | AC | 387 ms
45,064 KB |
testcase_04 | AC | 464 ms
44,248 KB |
testcase_05 | AC | 156 ms
33,976 KB |
testcase_06 | AC | 664 ms
46,956 KB |
testcase_07 | AC | 677 ms
49,800 KB |
testcase_08 | AC | 1,084 ms
51,824 KB |
testcase_09 | AC | 616 ms
49,900 KB |
testcase_10 | AC | 253 ms
33,576 KB |
testcase_11 | AC | 276 ms
36,260 KB |
testcase_12 | AC | 237 ms
36,520 KB |
testcase_13 | AC | 162 ms
32,620 KB |
testcase_14 | AC | 137 ms
33,748 KB |
testcase_15 | AC | 234 ms
34,600 KB |
testcase_16 | AC | 227 ms
32,936 KB |
testcase_17 | AC | 50 ms
27,600 KB |
testcase_18 | AC | 66 ms
32,040 KB |
testcase_19 | AC | 231 ms
33,980 KB |
testcase_20 | AC | 327 ms
47,664 KB |
testcase_21 | AC | 358 ms
42,524 KB |
testcase_22 | AC | 311 ms
49,112 KB |
testcase_23 | AC | 279 ms
48,612 KB |
testcase_24 | AC | 268 ms
44,672 KB |
testcase_25 | AC | 588 ms
46,912 KB |
testcase_26 | AC | 593 ms
50,972 KB |
testcase_27 | AC | 164 ms
36,356 KB |
testcase_28 | AC | 810 ms
51,776 KB |
testcase_29 | AC | 367 ms
43,532 KB |
testcase_30 | AC | 537 ms
48,548 KB |
testcase_31 | AC | 493 ms
50,048 KB |
testcase_32 | AC | 494 ms
46,588 KB |
testcase_33 | AC | 352 ms
47,120 KB |
testcase_34 | AC | 207 ms
38,068 KB |
testcase_35 | AC | 192 ms
36,192 KB |
testcase_36 | AC | 325 ms
39,940 KB |
testcase_37 | AC | 486 ms
46,904 KB |
testcase_38 | AC | 97 ms
31,856 KB |
testcase_39 | AC | 235 ms
34,992 KB |
testcase_40 | AC | 228 ms
33,068 KB |
testcase_41 | AC | 230 ms
32,732 KB |
testcase_42 | AC | 229 ms
32,716 KB |
testcase_43 | AC | 299 ms
46,776 KB |
testcase_44 | AC | 297 ms
44,612 KB |
testcase_45 | AC | 300 ms
48,576 KB |
testcase_46 | AC | 275 ms
45,420 KB |
testcase_47 | AC | 374 ms
46,540 KB |
testcase_48 | AC | 358 ms
48,588 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
#region itumono using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using static System.Math; using static Output; using static Consts; #region I/O public static class Output { public static void Put(string a) => Console.WriteLine(a); public static void Put(params object[] i) => Put(string.Join(" ", i)); public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a)); public static void PutV<T>(IEnumerable<T> a) { foreach (var z in a) Put(z); } public static void YN(bool i) { if (i) Put("Yes"); else Put("No"); } } public class Input { public static string Str => Console.ReadLine(); public static bool IsTypeEqual<T, U>() => typeof(T).Equals(typeof(U)); public static T ConvertType<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); public static T Cast<T>(string s) { if (IsTypeEqual<T, int>()) return ConvertType<T, int>(int.Parse(s)); else if (IsTypeEqual<T, long>()) return ConvertType<T, long>(long.Parse(s)); else if (IsTypeEqual<T, double>()) return ConvertType<T, double>(double.Parse(s)); else if (IsTypeEqual<T, char>()) return ConvertType<T, char>(char.Parse(s)); else if (IsTypeEqual<T, BigInteger>()) return ConvertType<T, BigInteger>(BigInteger.Parse(s)); else if (IsTypeEqual<T, decimal>()) return ConvertType<T, decimal>(decimal.Parse(s)); else return ConvertType<T, string>(s); } public static T[] Castarr<T>(string[] s) { var ret = new T[s.Length]; int i = 0; if (IsTypeEqual<T, char>()) { var list = new List<T>(); foreach (var t in s) { foreach (var u in t) { list.Add(ConvertType<T, char>(char.Parse(u.ToString()))); } } return list.ToArray(); } foreach (var t in s) { if (IsTypeEqual<T, int>()) ret[i++] = ConvertType<T, int>(int.Parse(t)); else if (IsTypeEqual<T, long>()) ret[i++] = ConvertType<T, long>(long.Parse(t)); else if (IsTypeEqual<T, double>()) ret[i++] = ConvertType<T, double>(double.Parse(t)); else if (IsTypeEqual<T, BigInteger>()) ret[i++] = ConvertType<T, BigInteger>(BigInteger.Parse(t)); else ret[i++] = ConvertType<T, string>(t); } return ret; } Queue<string> q = new Queue<string>(); void next() { var ss = Str.Split(' '); foreach (var item in ss) q.Enqueue(item); } public T cin<T>() { if (!q.Any()) next(); return Cast<T>(q.Dequeue()); } public T[] cinarr<T>() { return Castarr<T>(Str.Split(' ')); } public T[] cinarr<T>(int n) { var ret = new T[n]; for (int i = 0; i < n; ++i) ret[i] = cin<T>(); return ret; } public int Int => cin<int>(); public long Long => cin<long>(); public double Double => cin<double>(); public char Char => cin<char>(); public string String => cin<string>(); public BigInteger BI => cin<BigInteger>(); public int[] Intarr => cinarr<int>(); public long[] Longarr => cinarr<long>(); public double[] Doublearr => cinarr<double>(); public char[] Chararr => cinarr<char>(); public string[] Stringarr => cinarr<string>(); public BigInteger[] BIarr => cinarr<BigInteger>(); public void cin<T>(out T t) { t = cin<T>(); } public void mul<T, U>(out T t, out U u) { t = cin<T>(); u = cin<U>(); } public void mul<T, U, V>(out T t, out U u, out V v) { t = cin<T>(); u = cin<U>(); v = cin<V>(); } public void mul<T, U, V, W>(out T t, out U u, out V v, out W w) { t = cin<T>(); u = cin<U>(); v = cin<V>(); w = cin<W>(); } public void mul<T, U, V, W, X>(out T t, out U u, out V v, out W w, out X x) { t = cin<T>(); u = cin<U>(); v = cin<V>(); w = cin<W>(); x = cin<X>(); } public void mul<T, U, V, W, X, Y>(out T t, out U u, out V v, out W w, out X x, out Y y) { t = cin<T>(); u = cin<U>(); v = cin<V>(); w = cin<W>(); x = cin<X>(); y = cin<Y>(); } public void mul<T, U, V, W, X, Y, Z>(out T t, out U u, out V v, out W w, out X x, out Y y, out Z z) { t = cin<T>(); u = cin<U>(); v = cin<V>(); w = cin<W>(); x = cin<X>(); y = cin<Y>(); z = cin<Z>(); } } #endregion class Program { static void Main(string[] args) { var CP = new CP(); CP.Solve(); } } #endregion itumono public static class Consts { public const int INF = 1 << 30; //public const long INF = 1L << 60; public const int MOD = 1000000007; //public const int MOD = 998244353; } public class CP { Input cin = new Input(); public void Solve() { var n = cin.Int; var m = cin.Int; var edge = Enumerable.Range(0, n).Select(_ => new List<(int to, int d)>()).ToArray(); for (int i = 0; i < m; ++i) { var s = cin.Int - 1; var t = cin.Int - 1; var d = cin.Int; edge[s].Add((t, d)); edge[t].Add((s, d)); } int ok = 0; int ng = INF; while (ng - ok > 1) { var cur = (ok + ng) / 2; if (BFS(0, edge, cur)[n - 1] != INF) ok = cur; else ng = cur; } Put(ok, BFS(0, edge, ok)[n - 1]); } public int[] BFS(int from, List<(int to, int d)>[] edge, int w) { var dist = Enumerable.Repeat(INF, edge.Length).ToArray(); dist[from] = 0; var q = new Queue<int>(); q.Enqueue(from); while (q.Any()) { var p = q.Dequeue(); foreach (var next in edge[p]) { if (dist[next.to] != INF) continue; if (next.d < w) continue; dist[next.to] = dist[p] + 1; q.Enqueue(next.to); } } return dist; } public int[] dijkstra(int from, List<(int to, int d)>[] edge, int max) { var ret = Enumerable.Repeat(INF, edge.Length).ToArray(); ret[from] = 0; var pq = new PriorityQueue<(int v, int d)>((a, b) => b.d - a.d); pq.Enqueue((from, 0)); while (pq.Any()) { var q = pq.Dequeue(); foreach (var next in edge[q.v]) { if (next.d < max) continue; if (ret[next.to] > q.d + 1) { ret[next.to] = q.d + 1; pq.Enqueue((next.to, ret[next.to])); } } } return ret; } } public class PriorityQueue<T> { List<T> _item; public int Count { get { return _item.Count; } } bool _isascend { get; set; } public T Peek { get { return _item[0]; } } Comparison<T> Comp; public PriorityQueue(bool IsAscend = true, IEnumerable<T> list = null) : this(Comparer<T>.Default.Compare, IsAscend, list) { } public PriorityQueue(Comparison<T> cmp, bool IsAscend = true, IEnumerable<T> list = null) { _item = new List<T>(); _isascend = IsAscend; this.Comp = cmp; if (list != null) { _item.AddRange(list); Build(); } } private int Compare(int i, int j) => (_isascend ? -1 : 1) * Comp(_item[i], _item[j]); private void Swap(int i, int j) { var t = _item[i]; _item[i] = _item[j]; _item[j] = t; } private int Parent(int i) => (i - 1) >> 1; private int Left(int i) => (i << 1) + 1; public T Enqueue(T val) { int i = _item.Count; _item.Add(val); while (i > 0) { int p = Parent(i); if (Compare(i, p) > 0) Swap(i, p); i = p; } return val; } private void Heapify(int index) { for (int i = index, j; (j = Left(i)) < _item.Count; i = j) { if (j != _item.Count - 1 && Compare(j, j + 1) < 0) j++; if (Compare(i, j) < 0) Swap(i, j); } } public T Dequeue() { T val = _item[0]; _item[0] = _item[_item.Count - 1]; _item.RemoveAt(_item.Count - 1); Heapify(0); return val; } private void Build() { for (var i = (_item.Count >> 1) - 1; i >= 0; i--) Heapify(i); } public bool Any() => Count > 0; }