ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#214393 | #2678. Small Multiple | KXG | 95 | 8092ms | 180964kb | C++11 | 1.0kb | 2024-11-18 19:47:24 | 2024-11-19 08:29:54 |
answer
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
int k, m;
bool vis[1000010];
long long d[1000010];
vector<pair<int, int> > G[1000010];
priority_queue<pair<long long, int> > pq;
void dijkstra() {
for (int i = 1; i < m; i++) {
d[i % k] = min(d[i % k], (long long)i);
pq.push({-d[i % k], i % k});
}
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++) {
if (d[G[t][i].first] > d[t] + G[t][i].second) {
d[G[t][i].first] = d[t] + G[t][i].second;
pq.push({-d[G[t][i].first], G[t][i].first});
}
}
}
}
int main() {
scanf("%d%d", &k, &m);
for (int i = 0; i < k; i++) {
d[i] = 1e18;
for (int j = 0; j < m; j++) {
G[i].push_back({(i * m + j) % k, j});
}
}
dijkstra();
printf("%lld\n", d[0]);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 0ms
memory: 24524kb
input:
32 4
output:
1
result:
ok single line: '1'
Test #2:
score: 5
Accepted
time: 4ms
memory: 24528kb
input:
25 6
output:
5
result:
ok single line: '5'
Test #3:
score: 5
Accepted
time: 3ms
memory: 24524kb
input:
19 3
output:
2
result:
ok single line: '2'
Test #4:
score: 5
Accepted
time: 9ms
memory: 24528kb
input:
64 7
output:
4
result:
ok single line: '4'
Test #5:
score: 5
Accepted
time: 7ms
memory: 24544kb
input:
86 10
output:
3
result:
ok single line: '3'
Test #6:
score: 5
Accepted
time: 4ms
memory: 24524kb
input:
17 2
output:
2
result:
ok single line: '2'
Test #7:
score: 5
Accepted
time: 835ms
memory: 180964kb
input:
937761 10
output:
6
result:
ok single line: '6'
Test #8:
score: 5
Accepted
time: 656ms
memory: 109424kb
input:
788944 8
output:
4
result:
ok single line: '4'
Test #9:
score: 5
Accepted
time: 350ms
memory: 64640kb
input:
573314 3
output:
4
result:
ok single line: '4'
Test #10:
score: 0
Time Limit Exceeded
input:
785883 5
output:
result:
Test #11:
score: 5
Accepted
time: 863ms
memory: 107692kb
input:
769025 7
output:
6
result:
ok single line: '6'
Test #12:
score: 5
Accepted
time: 811ms
memory: 91492kb
input:
909894 4
output:
3
result:
ok single line: '3'
Test #13:
score: 5
Accepted
time: 451ms
memory: 128324kb
input:
585472 9
output:
8
result:
ok single line: '8'
Test #14:
score: 5
Accepted
time: 467ms
memory: 101828kb
input:
795020 5
output:
4
result:
ok single line: '4'
Test #15:
score: 5
Accepted
time: 429ms
memory: 85588kb
input:
514716 8
output:
3
result:
ok single line: '3'
Test #16:
score: 5
Accepted
time: 831ms
memory: 126408kb
input:
984458 5
output:
4
result:
ok single line: '4'
Test #17:
score: 5
Accepted
time: 340ms
memory: 54372kb
input:
645285 2
output:
4
result:
ok single line: '4'
Test #18:
score: 5
Accepted
time: 490ms
memory: 144592kb
input:
694328 9
output:
8
result:
ok single line: '8'
Test #19:
score: 5
Accepted
time: 656ms
memory: 101596kb
input:
698907 6
output:
2
result:
ok single line: '2'
Test #20:
score: 5
Accepted
time: 886ms
memory: 143748kb
input:
994036 7
output:
2
result:
ok single line: '2'