QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#765135#8049. Equal Sumsint_RWA 0ms3668kbC++141.6kb2024-11-20 12:27:582024-11-20 12:28:04

Judging History

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

  • [2024-11-20 12:28:04]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3668kb
  • [2024-11-20 12:27:58]
  • 提交

answer

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#define ll long long
using namespace std;
const int mod=998244353;
int n,m;ll f[35][35][2],sum,ans,P=1;
struct node
{
    ll a[3][3];
    node operator * (const node o)
    {
        node z;memset(z.a,0,sizeof(z.a));
        for(int i:{0,1,2}) for(int j:{0,1,2}) for(int k:{0,1,2})
            z.a[i][j]=(z.a[i][j]+a[i][k]*o.a[k][j])%mod;
        return z;
    }
}g;
inline node ksm(node a,int b)
{
    node ans;memset(ans.a,0,sizeof(ans.a));
    for(int i:{0,1,2}) ans.a[i][i]=1;
    for(;b;a=a*a,b>>=1)
        if(b&1) ans=ans*a;return ans;
}
signed main()
{
#ifndef ONLINE_JUDGE
    freopen("in.in","r",stdin);
    freopen("out.out","w",stdout);
#endif
    cin.tie(0),cout.tie(0);
    ios::sync_with_stdio(0);
    cin>>n>>m,f[0][0][0]=1;
    for(int i=1;i<=30;++i)
    {
        if((m>>(i-1))&1)
        {
            for(int j=0;j<i;++j)
            {
                f[i][j+1][0]+=f[i-1][j][0];
                f[i][j][0]+=f[i-1][j][1];
                f[i][j][1]+=f[i-1][j][1];
            }
        }
        else
        {
            for(int j=0;j<i;++j)
            {
                f[i][j][0]+=f[i-1][j][0];
                f[i][j][1]+=f[i-1][j][0];
                f[i][j+1][1]+=f[i-1][j][1];
            }
        }
    }
    memset(g.a,0,sizeof(g.a));
    g.a[0][1]=g.a[1][0]=g.a[1][2]=g.a[2][0]=1;
    g=ksm(g,n),sum=(g.a[0][0]+g.a[1][1]+g.a[2][2])%mod;
    for(int j=0;j<=30;++j)
        ans+=P*f[30][j][0]%mod,P=P*sum%mod;
    cout<<ans%mod<<'\n';return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3668kb

input:

2 3
1 2
2 3
1 4
2 2
1 3

output:

4

result:

wrong answer 1st numbers differ - expected: '2', found: '4'