QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#79535 | #4841. Geometry | hos_lyric | WA | 144ms | 74124kb | C++14 | 5.4kb | 2023-02-20 11:28:44 | 2023-02-20 11:28:45 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
static constexpr unsigned M = M_;
unsigned x;
constexpr ModInt() : x(0U) {}
constexpr ModInt(unsigned x_) : x(x_ % M) {}
constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
ModInt pow(long long e) const {
if (e < 0) return inv().pow(-e);
ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
}
ModInt inv() const {
unsigned a = M, b = x; int y = 0, z = 1;
for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
assert(a == 1U); return ModInt(y);
}
ModInt operator+() const { return *this; }
ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
explicit operator bool() const { return x; }
bool operator==(const ModInt &a) const { return (x == a.x); }
bool operator!=(const ModInt &a) const { return (x != a.x); }
friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////
constexpr unsigned MO = 998244353;
using Mint = ModInt<MO>;
constexpr int LIM_INV = 6'000'010;
Mint inv[LIM_INV], fac[LIM_INV], invFac[LIM_INV];
void prepare() {
inv[1] = 1;
for (int i = 2; i < LIM_INV; ++i) {
inv[i] = -((Mint::M / i) * inv[Mint::M % i]);
}
fac[0] = invFac[0] = 1;
for (int i = 1; i < LIM_INV; ++i) {
fac[i] = fac[i - 1] * i;
invFac[i] = invFac[i - 1] * inv[i];
}
}
Mint binom(Int n, Int k) {
if (n < 0) {
if (k >= 0) {
return ((k & 1) ? -1 : +1) * binom(-n + k - 1, k);
} else if (n - k >= 0) {
return (((n - k) & 1) ? -1 : +1) * binom(-k - 1, n - k);
} else {
return 0;
}
} else {
if (0 <= k && k <= n) {
assert(n < LIM_INV);
return fac[n] * invFac[k] * invFac[n - k];
} else {
return 0;
}
}
}
// \prod_{i=0}^{l-1} \prod_{j=0}^{m-1} \prod_{k=0}^{n-1} (i+j+k+2)/(i+j+k+1)
Mint planePartition(int l, int m, int n) {
if (l > m) swap(l, m);
if (m > n) swap(m, n);
if (l > m) swap(l, m);
assert(l + m - 1 < LIM_INV);
Mint prod = 1;
for (int i = 1; i <= l + m - 1; ++i) {
prod *= (inv[i] * (i + n)).pow(min({i, l, l + m - i}));
}
return prod;
}
int main() {
prepare();
for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
int A, B, C;
scanf("%d%d%d", &A, &B, &C);
chmin(C, A + B);
const Int m = A + B - C;
const Int l = 2 * A - m;
const Int n = 2 * B - m;
Int area = (l+m+n)*(l+m+n) - l*l - m*m - n*n;
assert(area % 2 == 0);
area /= 2;
const Mint ans = planePartition(l, m, n);
printf("%lld %u\n", area, ans.x);
}
#ifndef LOCAL
break;
#endif
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 144ms
memory: 73896kb
input:
6 2 1 2 1 1 137 3 94 95 3 1998 1996 998244 353999 999999 50 120 150
output:
7 4 4 1 1124 31585548 23951 33873190 1289433675488 748596399 23600 480090154
result:
ok 12 numbers
Test #2:
score: 0
Accepted
time: 89ms
memory: 74124kb
input:
9 3 3 3 1 1 1 3 3 3 1 1 1 3 3 3 2 2 2 3 3 3 2 2 2 3 3 3
output:
27 980 3 2 27 980 3 2 27 980 12 20 27 980 12 20 27 980
result:
ok 18 numbers
Test #3:
score: 0
Accepted
time: 99ms
memory: 73824kb
input:
10 4 4 4 3 3 3 1 1 1 2 2 2 4 4 4 4 4 4 2 2 2 4 4 4 4 4 4 3 3 3
output:
48 232848 27 980 3 2 12 20 48 232848 48 232848 12 20 48 232848 48 232848 27 980
result:
ok 20 numbers
Test #4:
score: -100
Wrong Answer
time: 81ms
memory: 73928kb
input:
10 1 2 2 1 2 4 3 1 3 3 3 1 4 3 4 4 4 4 1 4 2 1 1 1 3 3 3 3 4 4
output:
7 4 8 1 11 6 11 6 39 14112 48 232848 7 166374059 3 2 27 980 39 14112
result:
wrong answer 13th numbers differ - expected: '8', found: '7'