QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#258515 | #7746. Go go Baron Bunny! | hos_lyric | AC ✓ | 58ms | 66308kb | C++14 | 5.7kb | 2023-11-19 19:34:04 | 2023-11-19 19:34:05 |
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 <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#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; }
#define COLOR(s) ("\x1b[" s "m")
////////////////////////////////////////////////////////////////////////////////
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 = 4'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;
}
}
}
Mint invTwo[LIM_INV];
Mint solve(Int N, Int K, Int T) {
Int M = 0;
for (; !(N <= M*(M+1)/2); ++M) {}
const Int R = N - (M-1)*M/2;
const Int G = __gcd(M, T);
const Int H = M / G;
const Int s = M - K;
cerr<<"N = "<<N<<", K = "<<K<<", T = "<<T<<": M = "<<M<<", R = "<<R<<", G = "<<G<<", H = "<<H<<", s = "<<endl;
if (!(s == 0 || s == 1)) {
return 0;
}
if (R % H != 0) {
return 0;
}
const Int A = R/H;
const Int B = G - R/H;
Mint ans = 0;
for (Int t = 0; t <= 1; ++t) for (Int p = 0; p <= A - 1; ++p) {
// [x^B] (x/(1-x))^(s+t+p)
if (B >= s+t+p) {
const Mint way = binom(A - 1, p) * binom(B - 1, B - (s+t+p));
const Int score = H * (p + t) + ((!t && s) ? (H - 1) : 0);
// cerr<<" s = "<<s<<", t = "<<t<<", p = "<<p<<": way = "<<way<<", score = "<<score<<endl;
ans += way * invTwo[score];
}
}
ans *= fac[K];
return ans;
}
int main() {
prepare();
const Mint INV2 = Mint(2).inv();
invTwo[0] = 1;
for (int i = 1; i < LIM_INV; ++i) {
invTwo[i] = invTwo[i - 1] * INV2;
}
Int N, K, T;
for (; ~scanf("%lld%lld%lld", &N, &K, &T); ) {
const Mint ans = solve(N, K, T);
printf("%u\n", ans.x);
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 46ms
memory: 66060kb
input:
2 1 2
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 49ms
memory: 66140kb
input:
8 4 2
output:
6
result:
ok 1 number(s): "6"
Test #3:
score: 0
Accepted
time: 49ms
memory: 66116kb
input:
29 7 154
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 38ms
memory: 66096kb
input:
50 10 10
output:
77225400
result:
ok 1 number(s): "77225400"
Test #5:
score: 0
Accepted
time: 38ms
memory: 66036kb
input:
50 9 10
output:
11362680
result:
ok 1 number(s): "11362680"
Test #6:
score: 0
Accepted
time: 41ms
memory: 66116kb
input:
2 1 1
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 58ms
memory: 66300kb
input:
20 6 15
output:
0
result:
ok 1 number(s): "0"
Test #8:
score: 0
Accepted
time: 42ms
memory: 66068kb
input:
31 7 62
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 0
Accepted
time: 54ms
memory: 66268kb
input:
1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #10:
score: 0
Accepted
time: 46ms
memory: 66124kb
input:
1 1 1000000000000
output:
1
result:
ok 1 number(s): "1"
Test #11:
score: 0
Accepted
time: 49ms
memory: 66092kb
input:
1000000 1414 999999999292
output:
626239238
result:
ok 1 number(s): "626239238"
Test #12:
score: 0
Accepted
time: 49ms
memory: 66288kb
input:
1000000 1413 999999999292
output:
804023673
result:
ok 1 number(s): "804023673"
Test #13:
score: 0
Accepted
time: 50ms
memory: 66092kb
input:
637704 1129 999999999368
output:
376288586
result:
ok 1 number(s): "376288586"
Test #14:
score: 0
Accepted
time: 32ms
memory: 66036kb
input:
777711 1246 999999999893
output:
315967293
result:
ok 1 number(s): "315967293"
Test #15:
score: 0
Accepted
time: 50ms
memory: 66060kb
input:
738077 1215 999999999405
output:
481429116
result:
ok 1 number(s): "481429116"
Test #16:
score: 0
Accepted
time: 53ms
memory: 66056kb
input:
878084 1324 999999999825
output:
85615210
result:
ok 1 number(s): "85615210"
Test #17:
score: 0
Accepted
time: 41ms
memory: 66100kb
input:
879744 1326 999999998712
output:
826681339
result:
ok 1 number(s): "826681339"
Test #18:
score: 0
Accepted
time: 46ms
memory: 66056kb
input:
519750 1019 999999999120
output:
380025867
result:
ok 1 number(s): "380025867"
Test #19:
score: 0
Accepted
time: 45ms
memory: 66140kb
input:
521410 1021 999999999509
output:
43307492
result:
ok 1 number(s): "43307492"
Test #20:
score: 0
Accepted
time: 38ms
memory: 66088kb
input:
578829 1075 999999999204
output:
847975635
result:
ok 1 number(s): "847975635"
Test #21:
score: 0
Accepted
time: 45ms
memory: 66032kb
input:
580490 1077 3
output:
0
result:
ok 1 number(s): "0"
Test #22:
score: 0
Accepted
time: 51ms
memory: 66300kb
input:
720496 1199 240
output:
0
result:
ok 1 number(s): "0"
Test #23:
score: 0
Accepted
time: 58ms
memory: 66092kb
input:
722157 1202 601
output:
952370308
result:
ok 1 number(s): "952370308"
Test #24:
score: 0
Accepted
time: 51ms
memory: 66112kb
input:
862163 1312 1313
output:
626393445
result:
ok 1 number(s): "626393445"
Test #25:
score: 0
Accepted
time: 39ms
memory: 66300kb
input:
822530 1283 1
output:
0
result:
ok 1 number(s): "0"
Test #26:
score: 0
Accepted
time: 57ms
memory: 66268kb
input:
962536 1386 1
output:
0
result:
ok 1 number(s): "0"
Test #27:
score: 0
Accepted
time: 45ms
memory: 66112kb
input:
1000000 1412 999999999292
output:
0
result:
ok 1 number(s): "0"
Test #28:
score: 0
Accepted
time: 49ms
memory: 66096kb
input:
1000000000 44721 999999975339
output:
510734471
result:
ok 1 number(s): "510734471"
Test #29:
score: 0
Accepted
time: 46ms
memory: 66060kb
input:
1000000000 44720 999999975339
output:
848193647
result:
ok 1 number(s): "848193647"
Test #30:
score: 0
Accepted
time: 53ms
memory: 66060kb
input:
842907373 41059 999999992564
output:
372008876
result:
ok 1 number(s): "372008876"
Test #31:
score: 0
Accepted
time: 45ms
memory: 66096kb
input:
509306715 31915 999999995252
output:
449159217
result:
ok 1 number(s): "449159217"
Test #32:
score: 0
Accepted
time: 58ms
memory: 66072kb
input:
724371023 38062 999999995226
output:
184015087
result:
ok 1 number(s): "184015087"
Test #33:
score: 0
Accepted
time: 45ms
memory: 66064kb
input:
890770366 42207 999999997728
output:
181797941
result:
ok 1 number(s): "181797941"
Test #34:
score: 0
Accepted
time: 45ms
memory: 66064kb
input:
900801961 42445 999999997945
output:
723246071
result:
ok 1 number(s): "723246071"
Test #35:
score: 0
Accepted
time: 54ms
memory: 66064kb
input:
567201303 33680 999999971049
output:
976667605
result:
ok 1 number(s): "976667605"
Test #36:
score: 0
Accepted
time: 43ms
memory: 66004kb
input:
782265611 39554 999999995722
output:
382214761
result:
ok 1 number(s): "382214761"
Test #37:
score: 0
Accepted
time: 54ms
memory: 66136kb
input:
743632241 38564 999999975555
output:
622113251
result:
ok 1 number(s): "622113251"
Test #38:
score: 0
Accepted
time: 46ms
memory: 66060kb
input:
753663836 38824 2
output:
0
result:
ok 1 number(s): "0"
Test #39:
score: 0
Accepted
time: 50ms
memory: 66304kb
input:
920063179 42896 181
output:
0
result:
ok 1 number(s): "0"
Test #40:
score: 0
Accepted
time: 57ms
memory: 66040kb
input:
635127486 35641 29
output:
0
result:
ok 1 number(s): "0"
Test #41:
score: 0
Accepted
time: 49ms
memory: 66296kb
input:
801526829 40037 40038
output:
966008245
result:
ok 1 number(s): "966008245"
Test #42:
score: 0
Accepted
time: 42ms
memory: 66060kb
input:
811558424 40288 4
output:
0
result:
ok 1 number(s): "0"
Test #43:
score: 0
Accepted
time: 54ms
memory: 66056kb
input:
977957767 44225 1134
output:
0
result:
ok 1 number(s): "0"
Test #44:
score: 0
Accepted
time: 41ms
memory: 66096kb
input:
1000000000 44719 999999975339
output:
0
result:
ok 1 number(s): "0"
Test #45:
score: 0
Accepted
time: 52ms
memory: 66256kb
input:
1000000000000 1414214 999999204684
output:
486279705
result:
ok 1 number(s): "486279705"
Test #46:
score: 0
Accepted
time: 55ms
memory: 66060kb
input:
1000000000000 1414213 999999204684
output:
480189439
result:
ok 1 number(s): "480189439"
Test #47:
score: 0
Accepted
time: 57ms
memory: 66112kb
input:
815496560693 811750096047 999999745266
output:
0
result:
ok 1 number(s): "0"
Test #48:
score: 0
Accepted
time: 49ms
memory: 66036kb
input:
582297122576 579821664123 999999766452
output:
0
result:
ok 1 number(s): "0"
Test #49:
score: 0
Accepted
time: 56ms
memory: 66260kb
input:
554379675168 1052976 999999724464
output:
850999094
result:
ok 1 number(s): "850999094"
Test #50:
score: 0
Accepted
time: 47ms
memory: 66300kb
input:
825475204348 1284892 999998814682
output:
718965161
result:
ok 1 number(s): "718965161"
Test #51:
score: 0
Accepted
time: 52ms
memory: 66308kb
input:
801852724236 1266375 999999350625
output:
266617066
result:
ok 1 number(s): "266617066"
Test #52:
score: 0
Accepted
time: 56ms
memory: 66300kb
input:
568653286119 1066445 999998949078
output:
268095321
result:
ok 1 number(s): "268095321"
Test #53:
score: 0
Accepted
time: 57ms
memory: 66068kb
input:
540735838711 1039938 999999181110
output:
955131707
result:
ok 1 number(s): "955131707"
Test #54:
score: 0
Accepted
time: 52ms
memory: 66068kb
input:
807536400595 1270854 999998944705
output:
83358005
result:
ok 1 number(s): "83358005"
Test #55:
score: 0
Accepted
time: 43ms
memory: 66060kb
input:
779618953187 1248694 624347
output:
695027909
result:
ok 1 number(s): "695027909"
Test #56:
score: 0
Accepted
time: 46ms
memory: 66132kb
input:
546419515070 1045388 1
output:
0
result:
ok 1 number(s): "0"
Test #57:
score: 0
Accepted
time: 47ms
memory: 66088kb
input:
527092002255 1026735 342245
output:
168868859
result:
ok 1 number(s): "168868859"
Test #58:
score: 0
Accepted
time: 54ms
memory: 66036kb
input:
793892564138 1260072 1
output:
0
result:
ok 1 number(s): "0"
Test #59:
score: 0
Accepted
time: 45ms
memory: 66112kb
input:
765975116731 1237720 44
output:
0
result:
ok 1 number(s): "0"
Test #60:
score: 0
Accepted
time: 54ms
memory: 66072kb
input:
532775678613 1032254 11865
output:
0
result:
ok 1 number(s): "0"
Test #61:
score: 0
Accepted
time: 54ms
memory: 66060kb
input:
1000000000000 1414212 999999204684
output:
0
result:
ok 1 number(s): "0"
Extra Test:
score: 0
Extra Test Passed