QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#601867 | #9381. 502 Bad Gateway | Zpairs | WA | 686ms | 3804kb | C++20 | 955b | 2024-09-30 14:54:32 | 2024-09-30 14:54:33 |
Judging History
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3800kb
input:
3 1 2 3
output:
1 1 3 2 2 1
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 686ms
memory: 3804kb
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'