QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#469643 | #8008. Fortune Wheel | xia_mc | RE | 0ms | 1328kb | C++14 | 1.9kb | 2024-07-09 21:27:22 | 2024-07-09 21:27:22 |
Judging History
answer
#include<cstdio>
#include<algorithm>
//static char buf[1000000],*p1=buf,*p2=buf,obuf[1000000],*p3=obuf;
//#define getchar() p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++
//#define putchar(x) (p3-obuf<1000000)?(*p3++=x):(fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=x)
template<typename dy> dy abs(dy x){return x>0?x:-x;}
template<typename dy> dy max(dy x,dy y){return x>y?x:y;}
template<typename dy> dy min(dy x,dy y){return x<y?x:y;}
template<typename dy> void swap(dy &x,dy &y){x^=y;y^=x;x^=y;}
template<typename dy>
void read(dy &x){
x=0;int f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
x*=f;
}
template<typename dy>
void write(dy x){
if(x<0){putchar('-');x=-x;}
if(x>9) write(x/10);
putchar(x%10+48);
}
void write(char x){putchar(x);}
void read(char *s){
while((*s=getchar())==' '||*s=='\n');
while((*++s=getchar())!=' '&&*s!='\n'&&*s!=EOF);
*s=0;
}
template<typename dy,typename... Args> void read(dy &x,Args &...args){read(x);read(args...);}
template<typename dy,typename... Args> void write(dy x,Args ...args){write(x);write(args...);}
const int N=505,inf=1e9;
int n,x,K,a[N],q[N],deep[N],id[N];
void bfs(int s){
int l=0,r=0;
q[r++]=s;deep[s]=1;
while(l<r){
int u=q[l++];
for(int i=1;i<=K;i++){
int v=u-a[i]+n>n?u-a[i]:u-a[i]+n;
if(!deep[v]){
q[r++]=v;
deep[v]=deep[u]+1;
}
}
}
for(int i=0;i<n;i++) if(!deep[i]) deep[i]=inf;else deep[i]--;
}
int main(){
read(n,x,K);
for(int i=1;i<=K;i++) read(a[i]);
bfs(0);int sum=0;
for(int i=0;i<n;i++) id[i]=i;
std::sort(id,id+n,[](int x,int y){return deep[x]<deep[y];});
int ans1=deep[x],ans2=1;
for(int i=0;i<n;i++){
if(deep[id[i]]==inf) break;
sum+=deep[id[i]];
int u=sum+n,v=i+1;
if(ans1*v>ans2*u) ans1=u,ans2=v;
}
int t=std::__gcd(ans1,ans2);
write(ans1/t,' ',ans2/t);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 1276kb
input:
6 3 2 2 4
output:
8 3
result:
ok 2 number(s): "8 3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 1328kb
input:
5 4 1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: -100
Runtime Error
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...