QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#581202 | #9381. 502 Bad Gateway | Kdlyh | WA | 175ms | 3696kb | C++20 | 2.8kb | 2024-09-22 10:37:23 | 2024-09-22 10:37:24 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
template <class T, size_t size = tuple_size<T>::value>
string to_debug(T, string s = "")
requires(not ranges::range<T>);
string to_debug(auto x)
requires requires(ostream& os) { os << x; }
{
return static_cast<ostringstream>(ostringstream() << x).str();
}
string to_debug(ranges::range auto x, string s = "")
requires(not is_same_v<decltype(x), string>)
{
for (auto& xi : x) {
s += ", " + to_debug(xi);
}
return "[" + s.substr(s.empty() ? 0 : 2) + "]";
}
template <class T, size_t size>
string to_debug(T x, string s)
requires(not ranges::range<T>)
{
[&]<size_t... I>(index_sequence<I...>) {
((s += ", " + to_debug(get<I>(x))), ...);
}(make_index_sequence<size>());
return "(" + s.substr(s.empty() ? 0 : 2) + ")";
}
#define debug(...) cerr << __LINE__ << ": (" #__VA_ARGS__ ") = " << to_debug(tuple(__VA_ARGS__)) << "\n"
#else
#define debug(X...)
#endif
using i64 = long long;
void pre_cal()
{
}
template<class T> struct Frac {
T x, y;
Frac() : Frac(0, 1) {}
Frac(T x_) : Frac(x_, 1) {}
Frac(T x_, T y_) : x(x_), y(y_) {
if (y < 0) {y = -y; x= -x;}
}
constexpr double val() const {
return 1.0 * x / y;
}
constexpr Frac norm() const {T p = gcd(x, y); return {x / p, y / p};}
friend constexpr auto &operator << (ostream& o, const Frac& j) {
T p = gcd(j.x, j.y);
if (j.y == p) {
return o << j.x / p;
} else {
return o << j.x / p << " " << j.y / p;
}
}
constexpr Frac &operator += (const Frac& i) {
return x = x * i.y + y * i.x, y *= i.y, *this;
}
constexpr Frac &operator *= (const Frac& i) {
return x *= i.x, y *= i.y, *this;
}
constexpr Frac &operator /= (const Frac& i) {
x *= i.y; y *= i.x; if (y < 0) {x = -x, y = -y;}
return *this;
}
friend constexpr bool operator < (const Frac i, const Frac j) {return i.x * j.y < i.y * j.x;}
friend constexpr bool operator == (const Frac i, const Frac j) {return i.x * j.y == i.y * j.x;}
};
void solve( )
{
#define tests
int n; cin >> n;
if (n < 6) {
if ((n + 1) % 2 == 0) {cout << (n + 1) / 2 << " " << 1 << "\n";}
else {cout << (n + 1) << " " << 2 << "\n";}
return ;
}
int k{std::sqrt(n) + 1};
i64 ans{1LL * (1 + 2 * k) * (2 * k) / 2};
Frac<i64> fenshu(1LL * k * 2 * k + n - (k * (k - 1)), k);
Frac<i64> sum = fenshu;
sum *= (n - (2 * k));
sum += ans;
sum /= n;
cout << sum << '\n';
}
signed main()
{
cin.tie(nullptr)->sync_with_stdio(false);
pre_cal();
int _{1};
#ifdef tests
cin >> _;
#endif
while (_--) {solve();}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3696kb
input:
3 1 2 3
output:
1 1 3 2 2 1
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 175ms
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 1999982504999985871 31623000000000 1 1 1 1 1999982504999985871 31623000000000 1 1 1999982504999985871 31623000000000 1 1 1 1 1 1 1999982504999985871 31623000000000 1 1 1 1 1999982504999985871 31623000000000 1 1 1999982504999985871 31623000000000 1999982504999985871 31623000000000 1 1 19999825049...
result:
wrong answer 2nd lines differ - expected: '1999961560 44721', found: '1999982504999985871 31623000000000'