ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#197454 | #3448. 心加心 | ddh123 | 100 | 458ms | 1560kb | C++11 | 1.1kb | 2023-11-12 10:33:32 | 2023-11-12 13:18:12 |
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define inf 0x3f3f3f3f3f3f3f3f
int n,p,l[5005],a[5005],dis[5001],pw[10005],minn;
bool vis[5001];
char s[205];
priority_queue<pii,vector<pii>,greater<pii>>q;
void dijkstra(){
while(q.size()){
int u=q.top().second;
q.pop();
if(vis[u])continue;
vis[u]=true;
for(int i=1;i<=n;i++){
int v=(u*pw[l[i]]+a[i])%p,w=l[i];
if(dis[u]+w<dis[v])
q.push({dis[v]=dis[u]+w,v});
}
}
}
signed main(){
scanf("%lld%lld",&n,&p),pw[0]=1;
for(int i=1;i<=2*p;i++)
pw[i]=pw[i-1]*10%p;
memset(dis,0x3f,sizeof(dis));
for(int i=1;i<=n;i++){
scanf("%s",s+1);
l[i]=strlen(s+1);
for(int j=1;j<=l[i];j++)
a[i]=((a[i]<<1)+(a[i]<<3)+(s[j]^48))%p;
q.push({dis[a[i]]=min(dis[a[i]],l[i]),a[i]});
}
dijkstra();
for(int i=0;i<p;i++){
minn=dis[(p-i)%p];
printf("%lld\n",(minn==inf?-1:minn));
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1292kb
input:
10 98 0 1 2 3 4 5 6 7 8 9
output:
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok 98 numbers
Test #2:
score: 10
Accepted
time: 25ms
memory: 1484kb
input:
5000 99 14781892056687055378359451878122218601921996058131918743098670380384485452067769009096639454...
output:
1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok 99 numbers
Test #3:
score: 10
Accepted
time: 0ms
memory: 1288kb
input:
3 99 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5 0 4 5...
output:
1 4 7 7 4 4 5 5 8 4 4 4 8 8 4 4 8 9 8 4 8 8 8 8 8 8 8 9 7 7 7 7 7 6 5 5 5 5 6 3 3 3 7 6 2 2 5 5 6 2 ...
result:
ok 99 numbers
Test #4:
score: 10
Accepted
time: 0ms
memory: 1288kb
input:
6 95 0 2 3 5 6 9 0 2 3 5 6 9 0 2 3 5 6 9 0 2 3 5 6 9 0 2 3 5 6 9 0 2 3 5 6 9 0 2 3 5 6 9 0 2 3 5 6 9...
output:
1 3 2 2 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 2 2 3 2 2 3 2 2 3 3 2 2 3 2 2 3 2 3 3 3 3 ...
result:
ok 95 numbers
Test #5:
score: 10
Accepted
time: 0ms
memory: 1288kb
input:
5 3 412 986 7687 79583 8318
output:
6 3 3
result:
ok 3 number(s): "6 3 3"
Test #6:
score: 10
Accepted
time: 0ms
memory: 1284kb
input:
5 3 5387 39817 6 6804 1
output:
1 2 1
result:
ok 3 number(s): "1 2 1"
Test #7:
score: 10
Accepted
time: 25ms
memory: 1484kb
input:
5000 100 4662215847345417996058539422385909140989122582319939315897492645456767910985172332639303829...
output:
180 180 180 180 180 180 180 180 180 180 180 181 180 180 180 181 180 180 180 181 181 180 180 181 180 ...
result:
ok 100 numbers
Test #8:
score: 10
Accepted
time: 27ms
memory: 1488kb
input:
5000 100 6017404839398900982117908052227697611177103082938397805192623914538500903540418343249962031...
output:
180 180 180 181 182 180 180 181 180 181 180 180 180 180 180 180 180 180 180 180 180 181 180 180 180 ...
result:
ok 100 numbers
Test #9:
score: 10
Accepted
time: 188ms
memory: 1556kb
input:
5000 5000 173577890992330520159895384217403731027027923558584792233344058149389687419038746812531024...
output:
196 184 183 192 192 195 -1 181 194 199 180 -1 180 -1 -1 -1 190 194 -1 185 182 -1 -1 -1 188 184 -1 19...
result:
ok 5000 numbers
Test #10:
score: 10
Accepted
time: 193ms
memory: 1560kb
input:
5000 5000 109684703722761599523811752824414002980896386859466348397242225190298237477285061568577404...
output:
184 180 191 185 195 195 -1 182 181 183 199 -1 192 -1 -1 -1 181 182 -1 185 -1 188 189 190 -1 190 188 ...
result:
ok 5000 numbers
Extra Test:
score: 0
Extra Test Passed