QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#470197 | #8008. Fortune Wheel | lichenyu_ac | RE | 0ms | 0kb | C++14 | 878b | 2024-07-10 11:11:11 | 2024-07-10 11:11:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int s,t;
int n,m,a[N];
bool v[N];
int d[N];
int bfs(int s){
memset(d,0x3f,sizeof(d));
memset(v,0,sizeof(v));
d[0]=0;
queue<int>q;
q.push(s);
while(q.size()){
int x=q.front();q.pop();
if(v[x])continue;
v[x]=1;
for(int i=1;i<=m;i++){
int y=(x-a[i]+n)%n;
if(d[y]>d[x]+1){
d[y]=d[x]+1;
q.push(y);
}
}
}
}
int gcd(int a,int b){
return b?gcd(b,a%b):a;
}
int main(){
scanf("%d%d%d",&n,&s,&m);
for(int i=1;i<=m;i++)scanf("%d",&a[i]);
int ans=0,cnt=0;
bfs(0);
for(int i=0;i<n;i++){
if(d[i]==0x3f3f3f3f)continue;
ans+=d[i];
// printf("%d %d\n",i,dist);
cnt++;
}
ans+=n;
int D=gcd(ans,cnt);
ans/=D,cnt/=D;
int dist=d[s];
if((long long)dist*cnt<ans)printf("%d 1\n",dist);
else printf("%d %d\n",ans,cnt);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
6 3 2 2 4