QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#764699#9479. And DNAZauneseWA 0ms4100kbC++141.2kb2024-11-20 10:16:062024-11-20 10:16:11

Judging History

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

  • [2024-11-20 10:16:11]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4100kb
  • [2024-11-20 10:16:06]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<unordered_map>

#define fi first
#define se second
#define mkp std::make_pair
using ll=long long;
using llu=unsigned long long;
using std::max;
using std::min;
template<class T> void cmax(T&a,T b){a=max(a,b);}
template<class T> void cmin(T&a,T b){a=min(a,b);}

const ll mod=998244353;

struct MAT{
    int a[3][3];
    MAT(){memset(a,0,sizeof a);}
};
MAT operator*(MAT a,MAT b){
    MAT c;
    for(int i=0;i<3;++i)
    for(int j=0;j<3;++j)
    for(int k=0;k<3;++k)
        c.a[i][j]=(c.a[i][j]+(ll)a.a[i][k]*b.a[k][j])%mod;
    return c;
}

namespace xm{
    void _(){
        int N,M;

        scanf("%d%d",&N,&M);

        MAT I,T;
        I.a[0][0]=I.a[1][1]=I.a[2][2]=1;
        T.a[0][1]=T.a[0][2]=T.a[1][0]=T.a[2][1]=1;
        for(int k=N;k;k>>=1,T=T*T) if(k&1) I=I*T;

        ll Z=(I.a[0][0]+I.a[1][1]+I.a[2][2])%mod;
        std::unordered_map<int,ll> dp;
        auto f=[&](auto&&self,int x)->ll{
            if(x<=1) return x?Z:1;
            if(dp.count(x)) return dp[x];
            if(x&1) return dp[x]=Z*self(self,x/2)%mod;
            return dp[x]=(self(self,x/2)+self(self,x/2-1))%mod;
        };
        printf("%lld\n",f(f,M));
    }
}

int main(){
    xm::_();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3804kb

input:

3 2

output:

4

result:

ok "4"

Test #2:

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

input:

3 0

output:

1

result:

ok "1"

Test #3:

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

input:

100 100

output:

343406454

result:

ok "343406454"

Test #4:

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

input:

686579306 119540831

output:

260602195

result:

ok "260602195"

Test #5:

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

input:

26855095 796233790

output:

492736984

result:

ok "492736984"

Test #6:

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

input:

295310488 262950628

output:

503008241

result:

ok "503008241"

Test #7:

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

input:

239670714 149827706

output:

994702969

result:

ok "994702969"

Test #8:

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

input:

790779949 110053353

output:

898252188

result:

ok "898252188"

Test #9:

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

input:

726600542 795285932

output:

183726777

result:

ok "183726777"

Test #10:

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

input:

957970519 585582861

output:

-383760976

result:

wrong answer 1st words differ - expected: '298814018', found: '-383760976'