QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#756#470948#8008. Fortune WheelczcZi_GaoFailed.2024-07-30 11:45:092024-07-30 11:45:09

詳細信息

Extra Test:

Accepted
time: 1ms
memory: 3980kb

input:

1 0 1
1

output:

0 1 

result:

ok 2 number(s): "0 1"

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#470948#8008. Fortune WheelZi_GaoAC ✓91ms4324kbC++141.4kb2024-07-10 17:00:232024-07-30 15:41:31

answer

#include<bits/stdc++.h>
// #define ONLINE_JUDGE
#define INPUT_DATA_TYPE long long
#define OUTPUT_DATA_TYPE long long
inline __attribute((always_inline)) INPUT_DATA_TYPE read(){register INPUT_DATA_TYPE x=0;register char f=0,c=getchar();while(c<'0'||'9'<c)f=(c=='-'),c=getchar();while('0'<=c&&c<='9')x=(x<<3)+(x<<1)+(c&15),c=getchar();return f?-x:x;}void print(OUTPUT_DATA_TYPE x){if(x<0)x=-x,putchar('-');if(x>9)print(x/10);putchar(x%10^48);return;}

int K[510],dis[100010];

int main(){
	#ifndef ONLINE_JUDGE
	freopen("name.in", "r", stdin);
	freopen("name.out", "w", stdout);
	#endif

    register int i,u,v;
    register long long resa,resb,sum=0,gcd;
    int n=read();
    int x=read();
    int m=read();

    for(i=0;i<m;++i) K[i]=read();
    std::queue<int> q;
    memset(dis,0x3f,sizeof(dis));
    dis[0]=0;
    q.push(0);
    while(!q.empty()){
        u=q.front(),q.pop();
        for(i=0;i<m;++i)
            if(dis[v=(u+n-K[i])%n]==0x3f3f3f3f)
                dis[v]=dis[u]+1,q.push(v);
    }

    resa=dis[x],resb=1;
    sum=n;
    std::sort(dis,dis+n);
    for(i=1;i<=n;++i){
        sum+=dis[i-1];
        if(resa*i>resb*sum)
            resa=sum,resb=i;
    }

    gcd=std::__gcd(resa,resb);
    resa/=gcd,resb/=gcd;
    print(resa),putchar(' '),print(resb),putchar(' ');

	#ifndef ONLINE_JUDGE
	fclose(stdin);
	fclose(stdout);
	#endif
    return 0;
}