QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#584503 | #9381. 502 Bad Gateway | KULIANLEN | WA | 384ms | 3664kb | C++17 | 1.6kb | 2024-09-23 14:54:33 | 2024-09-23 14:54:36 |
Judging History
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 = (1 + sq) / 2;
auto calc = [&](int x) -> pii {
x = min(x, t + 1);
int len = x - 1;
int res = 0;
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);
}
return ans;
};
pii ans = calc(x);
pii ans1 = calc(x + 1);
if(ans1.first * ans.second < ans1.second * ans.first)
{
ans = ans1;
}
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: 3664kb
input:
3 1 2 3
output:
1 1 3 2 2 1
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 384ms
memory: 3656kb
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 -1574441556123 13122558593750 1 1 1 1 -1574441556123 13122558593750 1 1 -1574441556123 13122558593750 1 1 1 1 1 1 -1574441556123 13122558593750 1 1 1 1 -1574441556123 13122558593750 1 1 -1574441556123 13122558593750 -1574441556123 13122558593750 1 1 -1574441556123 13122558593750 1 1 1 1 -1574441...
result:
wrong answer 2nd lines differ - expected: '1999961560 44721', found: '-1574441556123 13122558593750'