QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#864182#9479. And DNAxie_lzhWA 1ms3712kbC++141.4kb2025-01-20 11:27:042025-01-20 11:27:05

Judging History

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

  • [2025-01-20 11:27:05]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3712kb
  • [2025-01-20 11:27:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,mod=998244353;
int n,m;
void add(int &x,int y){ (x+=y)>=mod?x-=mod:x=x; }
struct Matrix
{
    int a[3][3];
    int* operator [](int x){ return a[x]; }
    void clear(){ memset(a,0,sizeof a); }
}B,F;
Matrix operator *(Matrix x,Matrix y)
{
    Matrix res; res.clear();
    for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
    for(int k=0;k<3;k++)
        add(res[i][j],1ll*x[i][k]*y[k][j]%mod);
    return res;
}
Matrix ksm(Matrix x,int k)
{
    k--; Matrix res=x;
    for(;k;k>>=1,x=x*x)
        if(k&1) res=res*x;
    return res;
}
int f[40][2];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin>>n>>m;
    B[0][1]=B[1][2]=B[1][0]=B[2][0]=1;
    F.clear(); F[0][0]=1;
    int w=0;
    Matrix nx=F*ksm(B,n-1);
    add(w,nx[0][1]+nx[0][2]);
    F.clear(); F[0][1]=1;
    nx=F*ksm(B,n-1);
    add(w,nx[0][0]);
    F.clear(); F[0][0]=1;
    nx=F*ksm(B,n-2);
    add(w,nx[0][1]);
    if(m&1) f[0][0]=w;
    else f[0][0]=f[0][1]=1;
    for(int i=1;i<=32;i++)
    {
        if(m>>i&1)
        {
            f[i][0]=(1ll*f[i-1][0]*w%mod+f[i-1][1])%mod;
            f[i][1]=f[i-1][1];
        }
        else
        {
            f[i][0]=f[i-1][0];
            f[i][1]=(1ll*f[i-1][1]*w%mod+f[i-1][0])%mod;
        }
    }
    cout<<f[32][0]<<'\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3712kb

input:

3 2

output:

4

result:

ok "4"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3712kb

input:

3 0

output:

1

result:

ok "1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

100 100

output:

343406454

result:

ok "343406454"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3712kb

input:

686579306 119540831

output:

275606258

result:

wrong answer 1st words differ - expected: '260602195', found: '275606258'