Submission #2970516


Source Code Expand

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

typedef ll Weight;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void Dijkstra(const Graph &g, int s,
              vector<Weight> &dist, vector<int> &prev) {
    int n = (int)g.size();
    dist.assign(n, INF); dist[s] = 0;
    prev.assign(n, -1);
    priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
    for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
        Edge e = Q.top(); Q.pop();
        if (prev[e.dst] != -1) continue;
        prev[e.dst] = e.src;
        for(Edge f: g[e.dst]) {
            if (dist[f.dst] > e.weight+f.weight) {
                dist[f.dst] = e.weight+f.weight;
                Q.push(Edge(f.src, f.dst, e.weight+f.weight));
            }
        }
    }
}
int main() {
  int K;cin >> K;
  Graph g(K);
  repeat(i,K-1){
    g[i+1].push_back({(int)i+1,(int)(i+2)%K,1});
    g[i+1].push_back({(int)i+1,(int)(i+1)*10%K,0});
  }
  vector<Weight> dist;
  vint prev;
  Dijkstra(g,1,dist,prev);
  cout << dist[0]+1 << endl;
  return 0;
}

Submission Info

Submission Time
Task D - Small Multiple
User hashiryo
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1997 Byte
Status AC
Exec Time 40 ms
Memory 9592 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 67
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 1 ms 384 KB
02.txt AC 1 ms 256 KB
03.txt AC 1 ms 256 KB
04.txt AC 1 ms 256 KB
05.txt AC 1 ms 256 KB
06.txt AC 1 ms 256 KB
07.txt AC 1 ms 256 KB
08.txt AC 1 ms 256 KB
09.txt AC 1 ms 256 KB
10.txt AC 1 ms 256 KB
11.txt AC 1 ms 256 KB
12.txt AC 1 ms 256 KB
13.txt AC 1 ms 256 KB
14.txt AC 1 ms 256 KB
15.txt AC 1 ms 256 KB
16.txt AC 1 ms 256 KB
17.txt AC 1 ms 256 KB
18.txt AC 1 ms 256 KB
19.txt AC 1 ms 256 KB
20.txt AC 1 ms 256 KB
21.txt AC 26 ms 8704 KB
22.txt AC 27 ms 8704 KB
23.txt AC 32 ms 9592 KB
24.txt AC 40 ms 9592 KB
25.txt AC 30 ms 9084 KB
26.txt AC 29 ms 9084 KB
27.txt AC 33 ms 9592 KB
28.txt AC 31 ms 9592 KB
29.txt AC 33 ms 9084 KB
30.txt AC 38 ms 9592 KB
31.txt AC 1 ms 256 KB
32.txt AC 2 ms 256 KB
33.txt AC 29 ms 7420 KB
34.txt AC 12 ms 3712 KB
35.txt AC 28 ms 6652 KB
36.txt AC 30 ms 8444 KB
37.txt AC 8 ms 2560 KB
38.txt AC 13 ms 3712 KB
39.txt AC 17 ms 4992 KB
40.txt AC 3 ms 768 KB
41.txt AC 26 ms 7808 KB
42.txt AC 30 ms 8956 KB
43.txt AC 4 ms 1280 KB
44.txt AC 2 ms 640 KB
45.txt AC 16 ms 4864 KB
46.txt AC 20 ms 5632 KB
47.txt AC 3 ms 768 KB
48.txt AC 25 ms 8192 KB
49.txt AC 26 ms 7804 KB
50.txt AC 17 ms 5120 KB
51.txt AC 7 ms 2176 KB
52.txt AC 14 ms 4224 KB
53.txt AC 21 ms 6400 KB
54.txt AC 10 ms 3200 KB
55.txt AC 17 ms 4864 KB
56.txt AC 20 ms 6400 KB
57.txt AC 30 ms 8704 KB
58.txt AC 17 ms 5504 KB
59.txt AC 23 ms 7296 KB
60.txt AC 18 ms 5888 KB
61.txt AC 6 ms 1920 KB
62.txt AC 13 ms 4480 KB
63.txt AC 27 ms 8704 KB
64.txt AC 27 ms 8704 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB
s3.txt AC 21 ms 7040 KB