QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#767205#9479. And DNA5k_sync_closerWA 0ms1608kbC++141.3kb2024-11-20 20:10:452024-11-20 20:10:46

Judging History

你现在查看的是最新测评结果

  • [2024-11-20 20:10:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:1608kb
  • [2024-11-20 20:10:45]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

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'