QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#470139 | #8008. Fortune Wheel | c20251515 | WA | 1ms | 4636kb | C++20 | 925b | 2024-07-10 10:47:44 | 2024-07-10 10:47:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
const ll inf=0x3f3f3f3f3f3f3f3f;
ll n,x,m,k[N],ans=0;
ll dis[N];
ll sum=0,p=0,q=0;
void bfs(){
queue<ll> q;
memset(dis,inf,sizeof(dis));
dis[0]=0;
q.push(0);
while(!q.empty()){
ll u=q.front();
q.pop();
for(int i=1;i<=m;i++){
ll v=(u-k[i]+n)%n;
if(dis[v]==inf){
dis[v]=dis[u]+1;
q.push(v);
}
}
}
}
int main(){
cin>>n>>x>>m;
for(int i=1;i<=m;i++) cin>>k[i];
bfs();
sort(dis,dis+n);
p=dis[x];
q=1;
for(int i=0;i<n;i++){
if(dis[i]==inf) continue;
/*
最优策略要么先随机转动,再转动固定路径,要么直接可以转动固定路径
若从x随机转动跳到的点y,dis[y]>dis[x],则肯定不优,否则可以跳
*/
sum+=dis[i];
if((sum+n)*q<(i+1)*p){
p=sum+n;
q=i+1;
}
}
cout<<p/__gcd(p,q)<<" "<<q/__gcd(p,q);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4328kb
input:
6 3 2 2 4
output:
8 3
result:
ok 2 number(s): "8 3"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 4636kb
input:
5 4 1 1
output:
8 3
result:
wrong answer 1st numbers differ - expected: '1', found: '8'