QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#846009 | #9782. NonZero PrefSuf Sums | Milkcat2009 | AC ✓ | 8ms | 16548kb | C++14 | 3.6kb | 2025-01-06 21:03:26 | 2025-01-06 21:03:32 |
Judging History
answer
#include <bits/stdc++.h>
#define REP(i, l, r) for (int i = (l); i <= (r); ++ i)
#define DEP(i, r, l) for (int i = (r); i >= (l); -- i)
#define fi first
#define se second
#define pb emplace_back
#define mems(x, v) memset((x), (v), sizeof(x))
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
using namespace std;
namespace math {
typedef long long LL;
template <class T> T qpow(T a, LL b) { if (!b) return {1}; T rs = a; b --; for (; b; b >>= 1, a = a * a) if (b & 1) rs = rs * a; return rs; }
LL mul(LL a, LL b, LL p) { LL rs = a * b - LL(1.L * a * b / p) * p; rs %= p; if (rs < 0) rs += p; return rs; }
template <unsigned P = 0> struct mint {
unsigned v; static unsigned mod; mint() = default;
template <class T> mint(T x) { x %= getmod(), v = x < 0 ? x + getmod() : x; }
static int getmod() { if (P > 0) return P; else return mod; }
static void setmod(unsigned m) { mod = m; }
mint operator + () const { return *this; }
mint operator - () const { return mint(0) - *this; }
mint inv() const { return assert(v), qpow(*this, getmod() - 2); }
int val() const { return v; }
mint &operator += (const mint &q) { if (v += q.v, v >= getmod()) v -= getmod(); return *this; }
mint &operator -= (const mint &q) { if (v -= q.v, v >= getmod()) v += getmod(); return *this; }
mint &operator *= (const mint &q) { v = 1ull * v * q.v % getmod(); return *this; }
mint &operator /= (const mint &q) { return *this *= q.inv(); }
friend mint operator + (mint p, const mint &q) { return p += q; }
friend mint operator - (mint p, const mint &q) { return p -= q; }
friend mint operator * (mint p, const mint &q) { return p *= q; }
friend mint operator / (mint p, const mint &q) { return p /= q; }
friend bool operator == (const mint &p, const mint &q) { return p.v == q.v; }
friend bool operator != (const mint &p, const mint &q) { return p.v != q.v; }
friend bool operator < (const mint &p, const mint &q) { return p.v < q.v; }
friend bool operator > (const mint &p, const mint &q) { return p.v > q.v; }
friend bool operator <= (const mint &p, const mint &q) { return p.v <= q.v; }
friend bool operator >= (const mint &p, const mint &q) { return p.v >= q.v; }
friend istream &operator >> (istream &is, mint &a) { is >> a.v; return is; }
friend ostream &operator << (ostream &os, const mint &a) { os << a.v; return os; }
};
template <> unsigned mint<0>::mod = 998244353;
}
namespace Milkcat {
using namespace math;
typedef long long LL;
typedef pair<LL, LL> pii;
const int N = 105;
typedef mint<0> MI;
int n, m, mod; MI C[N][N], f[N][N][N], g[N][N * N * 2];
int main() {
cin >> n >> m >> mod, MI::setmod(mod);
int t = n * m; g[0][t] = 1, g[0][t + 1] = -1;
REP(i, 0, n) REP(j, 0, t * 2) {
if (j > 0) g[i][j] += g[i][j - 1];
g[i + 1][max(j - m, 0)] += g[i][j];
g[i + 1][min(j + m, t * 2) + 1] -= g[i][j];
}
MI rs = g[n][t]; C[0][0] = 1;
REP(x, 0, m) {
f[x][0][0] = 1, f[x][0][1] = -1;
REP(i, 0, n) REP(j, 0, n) {
if (j > 0) f[x][i][j] += f[x][i][j - 1];
f[x][i + 1][j] += f[x][i][j];
f[x][i + 1][min(j + x, n) + 1] -= f[x][i][j];
}
}
REP(i, 1, n) REP(j, 0, i) {
C[i][j] = C[i - 1][j];
if (j > 0) C[i][j] += C[i - 1][j - 1];
}
REP(x, 1, m) REP(S, 1, min(n, m / x + 1)) REP(i, S, n - 1) {
int v = i - S;
rs += (f[m / x][n - i][v] - (S > 1 ? f[S - 2][n - i][v] : 0)) * C[n][i] * 2;
}
cout << qpow((MI)m * 2 + 1, n) - rs << '\n';
return 0;
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int T = 1;
while (T --) Milkcat::main();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5604kb
input:
2 1 998244353
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 4ms
memory: 9672kb
input:
69 42 696969697
output:
378553557
result:
ok single line: '378553557'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5604kb
input:
2 1 998244353
output:
2
result:
ok single line: '2'
Test #4:
score: 0
Accepted
time: 4ms
memory: 9752kb
input:
69 42 696969697
output:
378553557
result:
ok single line: '378553557'
Test #5:
score: 0
Accepted
time: 0ms
memory: 11708kb
input:
61 75 677323601
output:
34613998
result:
ok single line: '34613998'
Test #6:
score: 0
Accepted
time: 0ms
memory: 5812kb
input:
13 14 670577333
output:
41465431
result:
ok single line: '41465431'
Test #7:
score: 0
Accepted
time: 1ms
memory: 7856kb
input:
14 6 987686347
output:
37536510
result:
ok single line: '37536510'
Test #8:
score: 0
Accepted
time: 1ms
memory: 5740kb
input:
15 12 196428923
output:
29322522
result:
ok single line: '29322522'
Test #9:
score: 0
Accepted
time: 1ms
memory: 6304kb
input:
68 7 786815587
output:
149281835
result:
ok single line: '149281835'
Test #10:
score: 0
Accepted
time: 1ms
memory: 5744kb
input:
3 2 503002109
output:
82
result:
ok single line: '82'
Test #11:
score: 0
Accepted
time: 1ms
memory: 5816kb
input:
13 5 756093197
output:
415698676
result:
ok single line: '415698676'
Test #12:
score: 0
Accepted
time: 1ms
memory: 5728kb
input:
2 3 646574611
output:
30
result:
ok single line: '30'
Test #13:
score: 0
Accepted
time: 3ms
memory: 8788kb
input:
39 68 120037189
output:
43217507
result:
ok single line: '43217507'
Test #14:
score: 0
Accepted
time: 0ms
memory: 5796kb
input:
13 4 423132517
output:
360231790
result:
ok single line: '360231790'
Test #15:
score: 0
Accepted
time: 0ms
memory: 5788kb
input:
14 3 309713387
output:
94215386
result:
ok single line: '94215386'
Test #16:
score: 0
Accepted
time: 2ms
memory: 8924kb
input:
24 77 886983941
output:
211636479
result:
ok single line: '211636479'
Test #17:
score: 0
Accepted
time: 0ms
memory: 5676kb
input:
3 3 504388063
output:
270
result:
ok single line: '270'
Test #18:
score: 0
Accepted
time: 1ms
memory: 5664kb
input:
3 1 936205423
output:
8
result:
ok single line: '8'
Test #19:
score: 0
Accepted
time: 1ms
memory: 5660kb
input:
3 3 295983139
output:
270
result:
ok single line: '270'
Test #20:
score: 0
Accepted
time: 1ms
memory: 5860kb
input:
10 15 446169107
output:
149884328
result:
ok single line: '149884328'
Test #21:
score: 0
Accepted
time: 1ms
memory: 6152kb
input:
37 18 833753929
output:
592917251
result:
ok single line: '592917251'
Test #22:
score: 0
Accepted
time: 1ms
memory: 5764kb
input:
11 3 998773403
output:
860630017
result:
ok single line: '860630017'
Test #23:
score: 0
Accepted
time: 1ms
memory: 8116kb
input:
14 85 688036639
output:
347188409
result:
ok single line: '347188409'
Test #24:
score: 0
Accepted
time: 0ms
memory: 5720kb
input:
3 3 844621907
output:
270
result:
ok single line: '270'
Test #25:
score: 0
Accepted
time: 1ms
memory: 5784kb
input:
3 4 204335891
output:
620
result:
ok single line: '620'
Test #26:
score: 0
Accepted
time: 1ms
memory: 7852kb
input:
7 8 113007667
output:
58946097
result:
ok single line: '58946097'
Test #27:
score: 0
Accepted
time: 1ms
memory: 7844kb
input:
4 1 637268377
output:
22
result:
ok single line: '22'
Test #28:
score: 0
Accepted
time: 1ms
memory: 5876kb
input:
11 14 391637237
output:
303270280
result:
ok single line: '303270280'
Test #29:
score: 0
Accepted
time: 1ms
memory: 5744kb
input:
3 2 208286231
output:
82
result:
ok single line: '82'
Test #30:
score: 0
Accepted
time: 1ms
memory: 5684kb
input:
2 11 662696483
output:
462
result:
ok single line: '462'
Test #31:
score: 0
Accepted
time: 0ms
memory: 6264kb
input:
19 55 974135299
output:
887460557
result:
ok single line: '887460557'
Test #32:
score: 0
Accepted
time: 0ms
memory: 5680kb
input:
6 8 417027509
output:
23351024
result:
ok single line: '23351024'
Test #33:
score: 0
Accepted
time: 1ms
memory: 7816kb
input:
8 13 624006587
output:
353008442
result:
ok single line: '353008442'
Test #34:
score: 0
Accepted
time: 0ms
memory: 5788kb
input:
10 10 740294671
output:
79436611
result:
ok single line: '79436611'
Test #35:
score: 0
Accepted
time: 1ms
memory: 7768kb
input:
11 10 394088657
output:
161476458
result:
ok single line: '161476458'
Test #36:
score: 0
Accepted
time: 0ms
memory: 7824kb
input:
9 27 562853573
output:
135252259
result:
ok single line: '135252259'
Test #37:
score: 0
Accepted
time: 1ms
memory: 5812kb
input:
8 3 829129009
output:
5349034
result:
ok single line: '5349034'
Test #38:
score: 0
Accepted
time: 0ms
memory: 9028kb
input:
51 49 924010279
output:
815049368
result:
ok single line: '815049368'
Test #39:
score: 0
Accepted
time: 1ms
memory: 5824kb
input:
12 2 308466749
output:
223013998
result:
ok single line: '223013998'
Test #40:
score: 0
Accepted
time: 1ms
memory: 5804kb
input:
7 4 567557693
output:
4502296
result:
ok single line: '4502296'
Test #41:
score: 0
Accepted
time: 3ms
memory: 9908kb
input:
36 93 943780729
output:
13599465
result:
ok single line: '13599465'
Test #42:
score: 0
Accepted
time: 1ms
memory: 5804kb
input:
2 1 828681127
output:
2
result:
ok single line: '2'
Test #43:
score: 0
Accepted
time: 1ms
memory: 7800kb
input:
3 3 534160729
output:
270
result:
ok single line: '270'
Test #44:
score: 0
Accepted
time: 1ms
memory: 7736kb
input:
7 12 920925433
output:
453086694
result:
ok single line: '453086694'
Test #45:
score: 0
Accepted
time: 1ms
memory: 5736kb
input:
3 2 440546987
output:
82
result:
ok single line: '82'
Test #46:
score: 0
Accepted
time: 0ms
memory: 6628kb
input:
90 9 291269963
output:
72560304
result:
ok single line: '72560304'
Test #47:
score: 0
Accepted
time: 0ms
memory: 5936kb
input:
38 10 867575113
output:
165530481
result:
ok single line: '165530481'
Test #48:
score: 0
Accepted
time: 2ms
memory: 6680kb
input:
48 37 152663531
output:
135425620
result:
ok single line: '135425620'
Test #49:
score: 0
Accepted
time: 1ms
memory: 7880kb
input:
15 15 991731803
output:
102703562
result:
ok single line: '102703562'
Test #50:
score: 0
Accepted
time: 8ms
memory: 16548kb
input:
100 100 696969697
output:
313377809
result:
ok single line: '313377809'
Extra Test:
score: 0
Extra Test Passed