QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#585670 | #9381. 502 Bad Gateway | KULIANLEN | WA | 449ms | 3676kb | C++20 | 1.8kb | 2024-09-23 21:43:12 | 2024-09-23 21:43:15 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
using ld = long double;
struct pii {
int first, second;
};
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()
{
long long xx;cin >> xx;
int t = xx;
int delta = 1 + 8 * t;
ld sq = sqrtl(delta);
int x = ceill((1 + sq) / 2);
// cout << (long long)(x * x - x - 2 * t) << endl;
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 << (long long)ans.first <<" " << (long long)ans.second << endl;
}
signed main()
{
ios::sync_with_stdio(false);cin.tie(0);
long long T;cin >> T;
while(T--)
solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3676kb
input:
3 1 2 3
output:
1 1 3 2 2 1
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 449ms
memory: 3560kb
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'