QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#581860#9381. 502 Bad GatewayKULIANLEN#WA 343ms3696kbC++171.4kb2024-09-22 14:23:482024-09-22 14:23:48

Judging History

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

  • [2024-09-24 14:55:37]
  • hack成功,自动添加数据
  • (/hack/886)
  • [2024-09-22 14:23:48]
  • 评测
  • 测评结果:WA
  • 用时:343ms
  • 内存:3696kb
  • [2024-09-22 14:23:48]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define endl '\n'
using ld = long double;
using pii = pair<int,int>;

pii add(pii a, pii b) {
    int x = a.first * b.second + a.second * b.first;
    int y = a.second * b.second;
    int d = gcd(x, y);
    return {x / d, y / d};
}   

pii mul(pii a, int k) {
    int x = a.first * k;
    int y = a.second;
    int d = gcd(x, y);
    return {x / d, y / d}; 
}

void solve()
{
    int t;cin >> t;
    int delta = 1 + 8 * t;
    ld sq = sqrtl(delta);
    int x = ceill((1 + sq) / 2);
    int res = 0;
    x = min(x, t + 1);
    int len = x - 1;
    res += (1 + len) * len / 2;
    pii ans = {res, t};
    // cout << len << endl;
    int d = gcd(ans.first, ans.second);
    ans = {ans.first / d, ans.second / d};
    if(t - x + 1 > 0)
    {
        pii tmp = mul(add({t, x - 1}, {x, 2}), t - x + 1);
        // cout << tmp.first <<" " << tmp.second << endl;
        tmp = {tmp.first, tmp.second * t};
        int d = gcd(tmp.first, tmp.second);
        tmp.first /= d;tmp.second /= d;
        // cout << ans.first <<" " << ans.second <<" " << tmp.first <<" " << tmp.second << endl;
        ans = add(ans, tmp);
    }
    
    cout << ans.first <<" " << ans.second << endl;


}


signed main() 
{
    ios::sync_with_stdio(false);cin.tie(0);
    int T;cin >> T;
    while(T--)
    solve();
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1
2
3

output:

1 1
3 2
2 1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 343ms
memory: 3696kb

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
28990158193688 23240529358089
1 1
1 1
28990158193688 23240529358089
1 1
28990158193688 23240529358089
1 1
1 1
1 1
28990158193688 23240529358089
1 1
1 1
28990158193688 23240529358089
1 1
28990158193688 23240529358089
28990158193688 23240529358089
1 1
28990158193688 23240529358089
1 1
1 1
28990158...

result:

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