QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#601864#9381. 502 Bad GatewayZpair#WA 683ms3860kbC++20955b2024-09-30 14:53:242024-09-30 14:53:24

Judging History

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

  • [2024-09-30 14:53:24]
  • 评测
  • 测评结果:WA
  • 用时:683ms
  • 内存:3860kb
  • [2024-09-30 14:53:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 i128;
i128 T,S;
struct frac{
	i128 x,y;
	bool operator <(const frac &ret)const{
		return x*ret.y<ret.x*y;
	}
};
frac ans;
frac get(i128 L){
	frac now={L*L*T-T*T*L+S,L};
	ans=min(ans,now);
	return now;
}
void solve(){
	ll _T;
	scanf("%lld",&_T);
	T=_T;
	S=T*(T+1)/2*T;
	ans.x=1e27,ans.y=1;
	i128 l=1,r=T,sz=(r-l)/3,m1=l+sz,m2=r-sz;
	while(l+10<=r){
		if(get(m1)<get(m2))
			r=m2-1;
		else l=m1+1;
		sz=(r-l)/3,m1=l+sz,m2=r-sz;
	}
	for(int i=l;i<=r;++i)
		get(i);
	ans.y*=T;
	i128 g=__gcd(ans.x,ans.y);
	ans.x/=g,ans.y/=g;
	ll x=ans.x,y=ans.y;
	printf("%lld %lld\n",x,y);
//	long double mn=1e30;
//	for(int L=1;L<=T;++L){
//		long double val=((long double)L*L*T-T*T*L+S)/L;
//		mn=min(mn,val);
//	}
//	printf("%.10Lf",mn*1.0/T);
}
int main(){
	int T;cin>>T;
	while(T--)solve();
}
/*
1
1000000000

414213563.0802018302
*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3848kb

input:

3
1
2
3

output:

1 1
3 2
2 1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 683ms
memory: 3860kb

input:

1000000
1
1000000000
1
1
1000000000
1
1000000000
1
1
1
1000000000
1
1
1000000000
1
1000000000
1000000000
1
1000000000
1
1
1000000000
1
1000000000
1000000000
1
1000000000
1000000000
1000000000
1000000000
1000000000
1000000000
1
1
1000000000
1
1000000000
1000000000
1000000000
1000000000
1
1
1
10000000...

output:

1 1
146446609825197762 353553391
1 1
1 1
146446609825197762 353553391
1 1
146446609825197762 353553391
1 1
1 1
1 1
146446609825197762 353553391
1 1
1 1
146446609825197762 353553391
1 1
146446609825197762 353553391
146446609825197762 353553391
1 1
146446609825197762 353553391
1 1
1 1
1464466098251977...

result:

wrong answer 2nd lines differ - expected: '1999961560 44721', found: '146446609825197762 353553391'