Submission #1786202
Source Code Expand
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; using static System.Console; //using System.Numerics; //using static System.Math; class Program { static void Main() { //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; void solve() { int K = cin.nextint; G = Enumerable.Range(0, K).Select(i => new List<Edge>()).ToArray(); for (int i = 0; i < K; i++) { G[i].Add(new Edge((i + 1) % K, 1)); G[i].Add(new Edge((i * 10) % K, 0)); } dijkstra(1); WriteLine(D[0] + 1); } // ref: http://abc070.contest.atcoder.jp/submissions/1505233 struct Edge : IComparable<Edge> { public int to; public long cost; public Edge(int to, long cost) { this.to = to; this.cost = cost; } public int CompareTo(Edge e) { return cost.CompareTo(e.cost); } } List<Edge>[] G; long[] D; const long inf = long.MaxValue / 3; void input(int n, int m) { G = Enumerable.Range(0, n).Select(i => new List<Edge>()).ToArray(); for (int i = 0; i < m; i++) { int a = cin.nextint - 1; int b = cin.nextint - 1; long c = cin.nextlong; G[a].Add(new Edge(b, c)); G[b].Add(new Edge(a, c)); } } void dijkstra(int s) { int n = G.Length; D = Enumerable.Repeat(inf, n).ToArray(); var Q = new PriorityQueue<Edge>();//小さい順に取り出すので要素に-1を掛ける D[s] = 0; Q.Enqueue(new Edge(s, D[s])); while (Q.Any()) { var e = Q.Dequeue(); var v = e.to; if (D[v] < -e.cost) continue; foreach (var gv in G[v]) { if (D[gv.to] > D[v] + gv.cost) { D[gv.to] = D[v] + gv.cost; Q.Enqueue(new Edge(gv.to, -D[gv.to])); } } } } class PriorityQueue<T> where T : IComparable<T> { List<T> heap; int size; int Compare(T x, T y) { return y.CompareTo(x); } public PriorityQueue() { heap = new List<T>(); } public void Enqueue(T x) { heap.Add(x); int i = size++; while (i > 0) { int p = (i - 1) >> 1; if (Compare(heap[p], x) <= 0) break; heap[i] = heap[p]; i = p; } heap[i] = x; } public T Dequeue() { T ret = heap[0]; T x = heap[--size]; int i = 0; while ((i << 1) + 1 < size) { int a = (i << 1) + 1; int b = (i << 1) + 2; if (b < size && Compare(heap[b], heap[a]) < 0) a = b; if (Compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public int Count { get { return size; } } public bool Any() { return size > 0; } public T Peek() { return heap[0]; } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan { get { return ReadLine().Split(); } } public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } } public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } } public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } } public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint { get { return int.Parse(next); } } public long nextlong { get { return long.Parse(next); } } public double nextdouble { get { return double.Parse(next); } } }
Submission Info
Submission Time | |
---|---|
Task | D - Small Multiple |
User | claw88 |
Language | C# (Mono 4.6.2.0) |
Score | 700 |
Code Size | 4755 Byte |
Status | AC |
Exec Time | 121 ms |
Memory | 38176 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt, s3.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, 57.txt, 58.txt, 59.txt, 60.txt, 61.txt, 62.txt, 63.txt, 64.txt, s1.txt, s2.txt, s3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 29 ms | 9508 KB |
02.txt | AC | 29 ms | 11476 KB |
03.txt | AC | 28 ms | 11476 KB |
04.txt | AC | 29 ms | 13524 KB |
05.txt | AC | 28 ms | 11476 KB |
06.txt | AC | 28 ms | 9428 KB |
07.txt | AC | 29 ms | 11476 KB |
08.txt | AC | 28 ms | 11476 KB |
09.txt | AC | 28 ms | 9428 KB |
10.txt | AC | 29 ms | 11476 KB |
11.txt | AC | 28 ms | 9428 KB |
12.txt | AC | 28 ms | 11476 KB |
13.txt | AC | 28 ms | 9428 KB |
14.txt | AC | 28 ms | 9428 KB |
15.txt | AC | 28 ms | 11476 KB |
16.txt | AC | 28 ms | 11476 KB |
17.txt | AC | 28 ms | 11476 KB |
18.txt | AC | 28 ms | 11476 KB |
19.txt | AC | 28 ms | 11476 KB |
20.txt | AC | 28 ms | 11476 KB |
21.txt | AC | 116 ms | 34080 KB |
22.txt | AC | 116 ms | 34080 KB |
23.txt | AC | 103 ms | 34616 KB |
24.txt | AC | 117 ms | 32444 KB |
25.txt | AC | 112 ms | 36128 KB |
26.txt | AC | 118 ms | 32032 KB |
27.txt | AC | 103 ms | 36540 KB |
28.txt | AC | 110 ms | 34364 KB |
29.txt | AC | 111 ms | 32032 KB |
30.txt | AC | 117 ms | 36412 KB |
31.txt | AC | 29 ms | 11476 KB |
32.txt | AC | 29 ms | 11476 KB |
33.txt | AC | 89 ms | 31816 KB |
34.txt | AC | 53 ms | 24836 KB |
35.txt | AC | 85 ms | 27144 KB |
36.txt | AC | 105 ms | 30868 KB |
37.txt | AC | 42 ms | 15200 KB |
38.txt | AC | 56 ms | 22492 KB |
39.txt | AC | 69 ms | 27148 KB |
40.txt | AC | 31 ms | 11744 KB |
41.txt | AC | 96 ms | 27120 KB |
42.txt | AC | 113 ms | 31804 KB |
43.txt | AC | 35 ms | 14176 KB |
44.txt | AC | 30 ms | 11492 KB |
45.txt | AC | 65 ms | 23084 KB |
46.txt | AC | 70 ms | 23192 KB |
47.txt | AC | 32 ms | 11616 KB |
48.txt | AC | 112 ms | 33228 KB |
49.txt | AC | 91 ms | 28968 KB |
50.txt | AC | 67 ms | 21108 KB |
51.txt | AC | 41 ms | 14944 KB |
52.txt | AC | 60 ms | 22956 KB |
53.txt | AC | 84 ms | 26624 KB |
54.txt | AC | 55 ms | 24516 KB |
55.txt | AC | 65 ms | 21036 KB |
56.txt | AC | 86 ms | 28548 KB |
57.txt | AC | 113 ms | 33732 KB |
58.txt | AC | 78 ms | 24980 KB |
59.txt | AC | 95 ms | 28736 KB |
60.txt | AC | 84 ms | 26160 KB |
61.txt | AC | 40 ms | 14816 KB |
62.txt | AC | 65 ms | 20544 KB |
63.txt | AC | 117 ms | 34080 KB |
64.txt | AC | 121 ms | 38176 KB |
s1.txt | AC | 29 ms | 11476 KB |
s2.txt | AC | 29 ms | 11476 KB |
s3.txt | AC | 94 ms | 26592 KB |