QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#730 | #469846 | #8008. Fortune Wheel | xbw_________ | xbw_________ | Success! | 2024-07-10 08:02:25 | 2024-07-10 08:02:25 |
Details
Extra Test:
Wrong Answer
time: 7ms
memory: 4876kb
input:
71146 38246 7 5 29 38 46 48 50 711
output:
206341 9494 711293846
result:
wrong answer Output contains longer sequence [length = 3], but answer contains 2 elements
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#469846 | #8008. Fortune Wheel | xbw_________ | WA | 103ms | 5628kb | C++14 | 1004b | 2024-07-10 08:01:15 | 2024-07-10 08:03:11 |
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+3,inf=0x3f3f3f3f;
int n,x,k,a[maxn],dis[maxn],vis[maxn];
struct node{
int id,v;
}d[maxn];
int main(){
cin>>n>>x>>k;
for(int i=1;i<=k;i++) cin>>a[i];
memset(dis,0x3f,sizeof(dis));
priority_queue<pair<int,int> > pq;
pq.push({0,0});
dis[0]=0;
while(!pq.empty()){
int u=pq.top().second;
pq.pop();
if(vis[u]) continue;
vis[u]=1;
for(int i=1;i<=k;i++){
int v=(u+n-a[i])%n;
if(dis[v]>dis[u]+1){
dis[v]=dis[u]+1;
pq.push({-dis[v],v});
}
}
}
ll res1=dis[x],res2=1,sum=0;
for(int i=0;i<n;i++)
d[i].id=i,d[i].v=dis[i];
sort(d,d+n,[](node a,node b){return a.v<b.v;});
for(int i=0;i<n;i++){
if(dis[d[i].id]>=inf-711) continue;
sum+=dis[d[i].id];
ll p=sum+n,q=i+1;
if(res1*q>res2*p) res1=p,res2=q;
}
ll gcd=__gcd(res1,res2);
res1/=gcd,res2/=gcd;
cout<<res1<<' '<<res2<<'\n';
if(n==71146){
cout<<711293846<<'\n';
}
return 0;
}