QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#767205 | #9479. And DNA | 5k_sync_closer | WA | 0ms | 1608kb | C++14 | 1.3kb | 2024-11-20 20:10:45 | 2024-11-20 20:10:46 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
#define M 998244353
#define int long long
using namespace std;
struct S
{
int a[3][3];
S() { memset(a, 0, sizeof a); }
S operator*(S b)
{
S c;
for (int i = 0; i < 3; ++i)
for (int k = 0; k < 3; ++k)
for (int j = 0; j < 3; ++j)
c.a[i][j] = (c.a[i][j] + a[i][k] * b.a[k][j]) % M;
return c;
}
} B, Z;
S P(S x, int y)
{
S q;
for (int i = 0; i < 3; ++i)
q.a[i][i] = 1;
for (; y; y >>= 1, x = x * x)
if (y & 1)
q = q * x;
return q;
}
int n, m, k, w, f[50][2];
signed main()
{
B.a[0][1] = B.a[0][2] = B.a[1][0] = B.a[2][1] = 1;
Z.a[0][0] = 3, Z.a[1][0] = 2;
scanf("%lld%lld", &n, &m), k = __lg(m);
w = (P(B, n - 3) * Z).a[0][0];
if (m & 1)
f[0][0] = w;
else
f[0][0] = f[0][1] = 1;
for (int i = 1; i <= k; ++i)
{
if (m >> i & 1)
{
f[i][0] = (f[i - 1][0] * w + f[i - 1][1]) % M;
f[i][1] = f[i - 1][1];
}
else
{
f[i][0] = f[i - 1][0] % M;
f[i][1] = (f[i - 1][0] + f[i - 1][1] * w) % M;
}
}
printf("%lld", f[k][0]);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 1608kb
input:
3 2
output:
4
result:
ok "4"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 1600kb
input:
3 0
output:
0
result:
wrong answer 1st words differ - expected: '1', found: '0'