UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#214407#2678. Small Multiplenodgd300ms1232kbC++11863b2024-11-18 20:22:042024-11-19 08:31:59

answer

#include <bits/stdc++.h>

using namespace std;

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

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

int main() {
    scanf("%d%d", &N, &M);
    for (int i = 0; i < N; i ++) {
        f[i] = INF32;
    }
    for (int i = 1; i < M; i ++) {
        int j = i % N;
        if (f[j] > i) {
            f[j] = 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 < M; i ++) {
            int y = (x * M + i) % N;
            if (f[y] > f[x] + i) {
                f[y] = f[x] + i;
                pq.push(make_pair(-f[y], y));
            }
        }
    }
    printf("%d\n", f[0]);
    return 0;
}

Details

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

Test #1:

score: 5
Accepted
time: 0ms
memory: 1228kb

input:

32 4

output:

1

result:

ok single line: '1'

Test #2:

score: 5
Accepted
time: 0ms
memory: 1232kb

input:

25 6

output:

5

result:

ok single line: '5'

Test #3:

score: 5
Accepted
time: 0ms
memory: 1232kb

input:

19 3

output:

2

result:

ok single line: '2'

Test #4:

score: 5
Accepted
time: 0ms
memory: 1228kb

input:

64 7

output:

4

result:

ok single line: '4'

Test #5:

score: 5
Accepted
time: 0ms
memory: 1232kb

input:

86 10

output:

3

result:

ok single line: '3'

Test #6:

score: 5
Accepted
time: 0ms
memory: 1228kb

input:

17 2

output:

2

result:

ok single line: '2'

Test #7:

score: 0
Runtime Error

input:

937761 10

output:


result:


Test #8:

score: 0
Runtime Error

input:

788944 8

output:


result:


Test #9:

score: 0
Runtime Error

input:

573314 3

output:


result:


Test #10:

score: 0
Runtime Error

input:

785883 5

output:


result:


Test #11:

score: 0
Runtime Error

input:

769025 7

output:


result:


Test #12:

score: 0
Runtime Error

input:

909894 4

output:


result:


Test #13:

score: 0
Runtime Error

input:

585472 9

output:


result:


Test #14:

score: 0
Runtime Error

input:

795020 5

output:


result:


Test #15:

score: 0
Runtime Error

input:

514716 8

output:


result:


Test #16:

score: 0
Runtime Error

input:

984458 5

output:


result:


Test #17:

score: 0
Runtime Error

input:

645285 2

output:


result:


Test #18:

score: 0
Runtime Error

input:

694328 9

output:


result:


Test #19:

score: 0
Runtime Error

input:

698907 6

output:


result:


Test #20:

score: 0
Runtime Error

input:

994036 7

output:


result: