Submission #40872957
Source Code Expand
/*+Rainybunny+*/
#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = l, rep##i = r; i <= rep##i; ++i)
#define per(i, r, l) for (int i = r, per##i = l; i >= per##i; --i)
const int N = 1e9, MOD = 998244353, INV6 = 166374059;
inline int mul(const int u, const int v) { return 1ll * u * v % MOD; }
inline void subeq(int& u, const int v) { (u -= v) < 0 && (u += MOD); }
inline int sub(int u, const int v) { return (u -= v) < 0 ? u + MOD : u; }
inline void addeq(int& u, const int v) { (u += v) >= MOD && (u -= MOD); }
inline int add(int u, const int v) { return (u += v) < MOD ? u : u - MOD; }
inline int mpow(int u, int v) {
int ret = 1;
for (; v; u = mul(u, u), v >>= 1) ret = mul(ret, v & 1 ? u : 1);
return ret;
}
struct Matrix {
static const int W = 6;
int mat[W + 1][W + 1];
inline int* operator [] (const int k) { return mat[k]; }
inline Matrix operator * (const Matrix & u) const {
Matrix ret{};
rep (i, 0, W) rep (k, 0, W) rep (j, 0, W) {
addeq(ret[i][j], mul(mat[i][k], u.mat[k][j]));
}
return ret;
}
};
inline Matrix matpow(Matrix u, int v) {
Matrix ret{};
rep (i, 0, Matrix::W) ret[i][i] = 1;
while (v) {
if (v & 1) ret = ret * u;
if (v >>= 1) u = u * u;
}
return ret;
}
const Matrix T = { {
{ 1 },
{ 0, 0, 1 },
{ 0, 0, 0, 1 },
{ 0, 0, 0, 0, 1 },
{ 0, 0, 0, 0, 0, 1 },
{ 0, 0, 0, 0, 0, 0, 1 },
{ 1, INV6, INV6, INV6, INV6, INV6, INV6 }
} };
inline Matrix init() {
Matrix F[12] = {}; F[11] = matpow(T, N - 11);
per (i, 10, 6) F[i] = F[i + 1] * T;
per (i, 5, 0) F[i][6][6 - i] = 1;
Matrix X{};
X[0][0] = 1;
rep (i, 1, 5) {
X[i][i] = 6, X[i][6] = 6;
rep (j, i + 1, i + 6) {
addeq(X[i][6], F[j][6][0]);
rep (k, 1, 6) subeq(X[i][6 - k], F[j][6][k]);
}
}
rep (i, 0, 5) {
int p = -1;
rep (j, i, 5) if (X[j][i]) { p = j; break; }
assert(~p);
if (i != p) std::swap(X.mat[i], X.mat[p]);
int inv = mpow(X[i][i], MOD - 2);
rep (j, i + 1, 5) {
int t = mul(inv, X[j][i]);
rep (k, i, 6) subeq(X[j][k], mul(t, X[i][k]));
}
}
per (i, 5, 0) {
X[i][6] = mul(X[i][6], mpow(X[i][i], MOD - 2));
rep (j, 0, i - 1) subeq(X[j][6], mul(X[j][i], X[i][6]));
}
Matrix F0 = { {
{ 1 },
{ X[5][6] }, { X[4][6] }, { X[3][6] },
{ X[2][6] }, { X[1][6] }, { X[0][6] }
} };
rep (i, 0, 5) fprintf(stderr, "%d%c", X[i][6], "\n "[i < 5]);
return F0;
}
int main() {
auto F0 = init();
int m; scanf("%d", &m), m = N - m;
if (m <= 5) printf("%d\n", F0[6 - m][0]);
else printf("%d\n", (matpow(T, N - 1 - m + 1) * F0)[6][0]);
return 0;
}
Submission Info
Submission Time
2023-04-22 22:19:46+0900
Task
Ex - Dice Sum Infinity
User
Rainybunny
Language
C++ (GCC 9.2.1)
Score
600
Code Size
2910 Byte
Status
AC
Exec Time
7 ms
Memory
3812 KiB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:98:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
98 | int m; scanf("%d", &m), m = N - m;
| ~~~~~^~~~~~~~~~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
600 / 600
Status
Set Name
Test Cases
Sample
00_sample_00.txt, 00_sample_01.txt
All
00_sample_00.txt, 00_sample_01.txt, 01_edge_02.txt, 01_edge_03.txt, 01_edge_04.txt, 01_edge_05.txt, 01_edge_06.txt, 01_edge_07.txt, 01_edge_08.txt, 01_edge_09.txt, 01_edge_10.txt, 01_edge_11.txt, 01_edge_12.txt, 01_edge_13.txt, 01_edge_14.txt, 01_edge_15.txt, 01_edge_16.txt, 01_edge_17.txt, 01_edge_18.txt, 01_edge_19.txt, 01_edge_20.txt, 01_edge_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt, 02_random_25.txt, 02_random_26.txt, 02_random_27.txt, 02_random_28.txt, 02_random_29.txt, 02_random_30.txt, 02_random_31.txt, 02_random_32.txt, 02_random_33.txt, 02_random_34.txt, 02_random_35.txt, 02_random_36.txt, 02_random_37.txt, 02_random_38.txt, 02_random_39.txt, 02_random_40.txt, 02_random_41.txt
Case Name
Status
Exec Time
Memory
00_sample_00.txt
AC
7 ms
3720 KiB
00_sample_01.txt
AC
2 ms
3744 KiB
01_edge_02.txt
AC
2 ms
3572 KiB
01_edge_03.txt
AC
2 ms
3792 KiB
01_edge_04.txt
AC
2 ms
3696 KiB
01_edge_05.txt
AC
1 ms
3636 KiB
01_edge_06.txt
AC
2 ms
3568 KiB
01_edge_07.txt
AC
2 ms
3576 KiB
01_edge_08.txt
AC
2 ms
3740 KiB
01_edge_09.txt
AC
2 ms
3744 KiB
01_edge_10.txt
AC
2 ms
3716 KiB
01_edge_11.txt
AC
2 ms
3808 KiB
01_edge_12.txt
AC
2 ms
3696 KiB
01_edge_13.txt
AC
2 ms
3572 KiB
01_edge_14.txt
AC
2 ms
3588 KiB
01_edge_15.txt
AC
2 ms
3704 KiB
01_edge_16.txt
AC
2 ms
3584 KiB
01_edge_17.txt
AC
2 ms
3708 KiB
01_edge_18.txt
AC
2 ms
3720 KiB
01_edge_19.txt
AC
2 ms
3696 KiB
01_edge_20.txt
AC
2 ms
3628 KiB
01_edge_21.txt
AC
2 ms
3792 KiB
02_random_22.txt
AC
2 ms
3716 KiB
02_random_23.txt
AC
1 ms
3808 KiB
02_random_24.txt
AC
2 ms
3632 KiB
02_random_25.txt
AC
2 ms
3740 KiB
02_random_26.txt
AC
2 ms
3812 KiB
02_random_27.txt
AC
2 ms
3696 KiB
02_random_28.txt
AC
2 ms
3636 KiB
02_random_29.txt
AC
3 ms
3576 KiB
02_random_30.txt
AC
1 ms
3696 KiB
02_random_31.txt
AC
2 ms
3672 KiB
02_random_32.txt
AC
2 ms
3700 KiB
02_random_33.txt
AC
2 ms
3692 KiB
02_random_34.txt
AC
2 ms
3580 KiB
02_random_35.txt
AC
2 ms
3716 KiB
02_random_36.txt
AC
2 ms
3568 KiB
02_random_37.txt
AC
4 ms
3568 KiB
02_random_38.txt
AC
2 ms
3632 KiB
02_random_39.txt
AC
2 ms
3708 KiB
02_random_40.txt
AC
2 ms
3716 KiB
02_random_41.txt
AC
2 ms
3812 KiB