ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#214466 | #2678. Small Multiple | naroto2022 | 100 | 6063ms | 72496kb | C++ | 1.3kb | 2024-11-18 22:43:44 | 2024-11-19 08:39:24 |
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#define ll long long
#define pll pair<ll,ll>
using namespace std;
const int MN=1e6+5;
const ll INF=1e15;
ll tot,head[MN],k,m,dis[MN];
bool vis[MN];
struct edge{ll to,nxt,w;}e[MN<<2];
void write(ll n){if(n<0){putchar('-');write(-n);return;}if(n>9)write(n/10);putchar(n%10+'0');}
ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
void add(ll u, ll v, ll w){e[++tot].nxt=head[u];head[u]=tot;e[tot].to=v;e[tot].w=w;}
void dijkstra(ll x){
priority_queue<pll,vector<pll>,greater<pll> > q;
for(int i=0; i<k; i++) dis[i]=INF;
dis[x]=0;q.push({0,x});
while(!q.empty()){
ll u=q.top().second;q.pop();
if(vis[u]) continue;
vis[u]=true;
for(int i=head[u]; i; i=e[i].nxt){
ll v=e[i].to,w=e[i].w;
if(dis[v]>dis[u]+w){
dis[v]=dis[u]+w;
q.push({dis[v],v});
}
}
}
}
int main(){
k=read();m=read();
for(int i=1; i<k; i++){
add(i,(i+1)%k,1);
add(i,(i*m)%k,0);
}
dijkstra(1);
write(dis[0]+1);
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 0ms
memory: 1188kb
input:
32 4
output:
1
result:
ok single line: '1'
Test #2:
score: 5
Accepted
time: 0ms
memory: 1180kb
input:
25 6
output:
5
result:
ok single line: '5'
Test #3:
score: 5
Accepted
time: 0ms
memory: 1180kb
input:
19 3
output:
2
result:
ok single line: '2'
Test #4:
score: 5
Accepted
time: 0ms
memory: 1188kb
input:
64 7
output:
4
result:
ok single line: '4'
Test #5:
score: 5
Accepted
time: 0ms
memory: 1188kb
input:
86 10
output:
3
result:
ok single line: '3'
Test #6:
score: 5
Accepted
time: 0ms
memory: 1180kb
input:
17 2
output:
2
result:
ok single line: '2'
Test #7:
score: 5
Accepted
time: 532ms
memory: 64736kb
input:
937761 10
output:
6
result:
ok single line: '6'
Test #8:
score: 5
Accepted
time: 442ms
memory: 53188kb
input:
788944 8
output:
4
result:
ok single line: '4'
Test #9:
score: 5
Accepted
time: 257ms
memory: 41596kb
input:
573314 3
output:
4
result:
ok single line: '4'
Test #10:
score: 5
Accepted
time: 552ms
memory: 59284kb
input:
785883 5
output:
2
result:
ok single line: '2'
Test #11:
score: 5
Accepted
time: 502ms
memory: 54020kb
input:
769025 7
output:
6
result:
ok single line: '6'
Test #12:
score: 5
Accepted
time: 446ms
memory: 67156kb
input:
909894 4
output:
3
result:
ok single line: '3'
Test #13:
score: 5
Accepted
time: 366ms
memory: 40276kb
input:
585472 9
output:
8
result:
ok single line: '8'
Test #14:
score: 5
Accepted
time: 496ms
memory: 53572kb
input:
795020 5
output:
4
result:
ok single line: '4'
Test #15:
score: 5
Accepted
time: 230ms
memory: 35784kb
input:
514716 8
output:
3
result:
ok single line: '3'
Test #16:
score: 5
Accepted
time: 622ms
memory: 71888kb
input:
984458 5
output:
4
result:
ok single line: '4'
Test #17:
score: 5
Accepted
time: 327ms
memory: 46168kb
input:
645285 2
output:
4
result:
ok single line: '4'
Test #18:
score: 5
Accepted
time: 324ms
memory: 47184kb
input:
694328 9
output:
8
result:
ok single line: '8'
Test #19:
score: 5
Accepted
time: 336ms
memory: 49568kb
input:
698907 6
output:
2
result:
ok single line: '2'
Test #20:
score: 5
Accepted
time: 631ms
memory: 72496kb
input:
994036 7
output:
2
result:
ok single line: '2'