UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213428#2355. DigitKXG100532ms19496kbC++111.1kb2024-11-11 22:06:442024-11-11 23:10:15

answer

#include <cstdio>
#include <queue>
#include <vector>
using namespace std;
int n, s, t;
vector<pair<int, int> > G[100010];
int d[100010];
bool vis[100010];
priority_queue<pair<int, int> > pq;
void dijkstra() {
    d[s] = 0;
    pq.push({0, s});
    while (!pq.empty()) {
        int t = pq.top().second;
        pq.pop();
        if (vis[t]) continue;
        vis[t] = true;
        for (int i = 0; i < G[t].size(); i++) {
            int v = G[t][i].first, w = G[t][i].second;
            if (d[v] > d[t] + w) {
                d[v] = d[t] + w;
                pq.push({-d[v], v});
            }
        }
    }
}
int main() {
    scanf("%d", &n);
    s = n;
    t = 0;
    for (int i = 0; i < n; i++) {
        d[i] = 1e9;
        for (int j = 0; j < 10; j++) {
            G[i].push_back({(i * 10 + j) % n, j * j});
            // printf("%d %d %d\n", i, (i * 10 + j) % n, j * j);
        }
    }
    for (int j = 1; j < 10; j++) {
        G[s].push_back({j % n, j * j});
        // printf("%d %d %d\n", s, j % n, j * j);
    }
    dijkstra();
    printf("%d\n", d[0]);
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 40ms
memory: 15832kb

input:

81920

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 10
Accepted
time: 39ms
memory: 12440kb

input:

55966

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 10
Accepted
time: 75ms
memory: 18824kb

input:

92661

output:

3

result:

ok 1 number(s): "3"

Test #4:

score: 10
Accepted
time: 75ms
memory: 15240kb

input:

68013

output:

18

result:

ok 1 number(s): "18"

Test #5:

score: 10
Accepted
time: 76ms
memory: 15956kb

input:

72927

output:

27

result:

ok 1 number(s): "27"

Test #6:

score: 10
Accepted
time: 9ms
memory: 5836kb

input:

15047

output:

5

result:

ok 1 number(s): "5"

Test #7:

score: 10
Accepted
time: 49ms
memory: 13028kb

input:

59994

output:

36

result:

ok 1 number(s): "36"

Test #8:

score: 10
Accepted
time: 84ms
memory: 19496kb

input:

97273

output:

10

result:

ok 1 number(s): "10"

Test #9:

score: 10
Accepted
time: 37ms
memory: 11740kb

input:

51139

output:

14

result:

ok 1 number(s): "14"

Test #10:

score: 10
Accepted
time: 48ms
memory: 12412kb

input:

55788

output:

15

result:

ok 1 number(s): "15"

Extra Test:

score: 0
Extra Test Passed