UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213381#2355. Digitnodgd100330ms3516kbC++11871b2024-11-11 21:07:592024-11-11 23:05:14

answer

#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 100000 + 5;
const int INF32 = 1e9;

int N, f[MAX_N];
priority_queue<pair<int,int>> pq;

int main() {
    scanf("%d", &N);
    for (int i = 0; i < N; i ++) {
        f[i] = INF32;
    }
    for (int i = 1; i <= 9; i ++) {
        int j = i % N;
        if (f[j] > i * i) {
            f[j] = i * i;
            pq.push(make_pair(-f[j], j));
        }
    }
    while (pq.size()) {
        auto tmp = pq.top();
        pq.pop();
        int x = tmp.second;
        if (tmp.first != -f[x]) continue;
        for (int i = 0; i <= 9; i ++) {
            int y = (x * 10 + i) % N;
            if (f[y] > f[x] + i * i) {
                f[y] = f[x] + i * i;
                pq.push(make_pair(-f[y], y));
            }
        }
    }
    printf("%d\n", f[0]);
    return 0;
}

详细

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

Test #1:

score: 10
Accepted
time: 12ms
memory: 2016kb

input:

81920

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 10
Accepted
time: 19ms
memory: 2304kb

input:

55966

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 10
Accepted
time: 45ms
memory: 3496kb

input:

92661

output:

3

result:

ok 1 number(s): "3"

Test #4:

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

input:

68013

output:

18

result:

ok 1 number(s): "18"

Test #5:

score: 10
Accepted
time: 63ms
memory: 3420kb

input:

72927

output:

27

result:

ok 1 number(s): "27"

Test #6:

score: 10
Accepted
time: 7ms
memory: 1588kb

input:

15047

output:

5

result:

ok 1 number(s): "5"

Test #7:

score: 10
Accepted
time: 31ms
memory: 2324kb

input:

59994

output:

36

result:

ok 1 number(s): "36"

Test #8:

score: 10
Accepted
time: 54ms
memory: 3516kb

input:

97273

output:

10

result:

ok 1 number(s): "10"

Test #9:

score: 10
Accepted
time: 27ms
memory: 2284kb

input:

51139

output:

14

result:

ok 1 number(s): "14"

Test #10:

score: 10
Accepted
time: 23ms
memory: 2304kb

input:

55788

output:

15

result:

ok 1 number(s): "15"

Extra Test:

score: 0
Extra Test Passed