QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#589763#9381. 502 Bad GatewayLanzyWA 327ms3860kbC++141.2kb2024-09-25 20:02:442024-09-25 20:02:44

Judging History

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

  • [2024-09-25 20:02:44]
  • 评测
  • 测评结果:WA
  • 用时:327ms
  • 内存:3860kb
  • [2024-09-25 20:02:44]
  • 提交

answer

#include <bits/stdc++.h>
#define int __int128
#define IOS ios::sync_with_stdio(0),cin.tie(0)

using namespace std;

const int N=2e5+10;

signed n;

double check(int x){
    if(x==0) return 1e18;
    if(x>n){
        return 1e18;
    }

    if(x==n){
        return (1+x)/2.0;
    }

    return (1+x)/2.0+1.0*n/x;
}

void add(int &fz,int &fm,int z,int m){

    int gcd=__gcd(fm,m);
    fz*=m/gcd;
    z*=fm/gcd;

    fz+=z;
    fm*=m/gcd;

    gcd=__gcd(fz,fm);
    fz/=gcd;
    fm/=gcd;
}

void sol(int cases){
    cin>>n;

    if(n==1){
        cout<<"1 1\n";
        return;
    }

    int L=1,R=n;
    while(L<=R){
        int mid=(L+R)>>1;
        if(check(mid)<=check(mid+1)){
            R=mid-1;
        }else{
            L=mid+1;
        }
    }

    int fz=1+L,fm=2;

    // cout<<L<<'\n';

    int gcd=__gcd(fz,fm);
    fz/=gcd;
    fm/=gcd;

    
    // cout<<fz<<' '<<fm<<'\n';


    // cout<<fz<<' '<<fm<<'\n';

    if(L!=n){
        add(fz,fm,n,L);
    }
    cout<<(long long)fz<<' '<<(long long)fm<<'\n';
}

signed main(){



    IOS;
    signed t=1;
    cin>>t;

    for(int i=1;i<=t;++i){
        sol(i);
    }

    return 0;
}

详细

Test #1:

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

input:

3
1
2
3

output:

1 1
3 2
2 1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 327ms
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
2000006281 44721
1 1
1 1
2000006281 44721
1 1
2000006281 44721
1 1
1 1
1 1
2000006281 44721
1 1
1 1
2000006281 44721
1 1
2000006281 44721
2000006281 44721
1 1
2000006281 44721
1 1
1 1
2000006281 44721
1 1
2000006281 44721
2000006281 44721
1 1
2000006281 44721
2000006281 44721
2000006281 44721
20...

result:

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