QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#469862#8008. Fortune WheellefyWA 39ms4712kbC++141.2kb2024-07-10 08:28:292024-07-10 08:28:29

Judging History

你现在查看的是最新测评结果

  • [2024-07-30 15:38:33]
  • hack成功,自动添加数据
  • (/hack/759)
  • [2024-07-10 08:28:29]
  • 评测
  • 测评结果:WA
  • 用时:39ms
  • 内存:4712kb
  • [2024-07-10 08:28:29]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+10,M=510;
int e[M],dis[N],n,K;
void get(){
    memset(dis,0x3f,sizeof(dis));
    dis[0]=0;queue<int>q;
    q.push(0);
    while(!q.empty()){
        int x=q.front();q.pop();
        for(int i=1;i<=K;i++){
            int nxt=(x+e[i])%n;
            if(dis[nxt]==0x3f3f3f3f){
                dis[nxt]=dis[x]+1;
                q.push(nxt);
            }
            nxt=(x-e[i]+n)%n;
            if(dis[nxt]==0x3f3f3f3f){
                dis[nxt]=dis[x]+1;
                q.push(nxt);
            }
        }
    }
}
int vis[N],id[N];
int cmp(int x,int y){
    return dis[x]<dis[y];
}
int gcd(int x,int y){
    if(!y)return x;
    return gcd(y,x%y);
}
int main(){
    int x;scanf("%d%d%d",&n,&x,&K);
    for(int i=1;i<=K;i++){
        scanf("%d",&e[i]);
    }
    sort(e+1,e+1+K);
    get();
    for(int i=0;i<n;i++)id[i]=i;
    sort(id+1,id+1+n,cmp);
    int p=dis[x],q=1,sum=0;
    for(int i=1;i<=n;i++)if(id[i]!=x){
        sum+=dis[id[i]];
        if((ll)p*i>(ll)q*(n+sum)){
            p=n+sum,q=i;int d=gcd(p,q);
            p/=d,q/=d;
        }
    }else break;
    printf("%d %d\n",p,q);
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 4452kb

input:

6 3 2
2 4

output:

8 3

result:

ok 2 number(s): "8 3"

Test #2:

score: 0
Accepted
time: 1ms
memory: 4452kb

input:

5 4 1
1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #3:

score: 0
Accepted
time: 39ms
memory: 4712kb

input:

99999 65238 100
64714 45675 36156 13116 93455 22785 10977 60219 14981 25839 83709 80404 41400 12469 31530 65521 35436 20326 96792 50699 27522 98233 26187 12509 90992 72693 83919 74145 80892 68422 38333 33497 89154 88403 77492 4570 3908 59194 3482 89871 96330 45114 5555 73987 95832 476 949 74649 2084...

output:

3 1

result:

ok 2 number(s): "3 1"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 4288kb

input:

10000 23 7
9594 8998 9330 6851 1662 6719 583

output:

6 1

result:

wrong answer 1st numbers differ - expected: '42726', found: '6'