QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#764596 | #9479. And DNA | zhanghuanrui | WA | 0ms | 3552kb | C++14 | 1.1kb | 2024-11-20 09:51:28 | 2024-11-20 09:52:08 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#ifdef zhr_debug
#define debug printf
#else
void debug(const char* s,...){}
#endif
using namespace std;
const int mod=998244353;
void add(int &x,int y){x+=y;if(x>=y)x-=mod;}
void freopen(string file){freopen((file+".in").c_str(),"r",stdin);freopen((file+".out").c_str(),"w",stdout);}
int n,m;
struct matrix
{
int a[3][3];
matrix(int x=0){memset(a,0,sizeof(a));a[0][0]=a[1][1]=a[2][2]=x;}
int* operator [] (const int x){return a[x];}
};
matrix operator * (matrix a,matrix b)
{
matrix ret(0);
for(int i=0;i<3;i++) for(int j=0;j<3;j++) for(int k=0;k<3;k++) add(ret[i][j],a[i][k]*b[k][j]%mod);
return ret;
}
matrix qpow(matrix x,int y)
{
static matrix ret;ret=1;
while(y)
{
if(y&1) ret=ret*x;
x=x*x;
y>>=1;
}
return ret;
}
matrix mul;
map<int,int> ans;
int dfs1(int x)
{
if(x==0) return 1;
if(ans.count(x)) return ans[x];
if(x&1) return ans[x]=dfs1(x>>1)*(mul[0][0]+mul[1][1]+mul[2][2])%mod;
return ans[x]=(dfs1(x>>1)+dfs1((x>>1)-1))%mod;
}
signed main()
{
cin>>n>>m;
mul[0][1]=mul[0][2]=mul[1][0]=mul[2][1]=1;
mul=qpow(mul,n);
cout<<dfs1(m);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3552kb
input:
3 2
output:
-998244349
result:
wrong answer 1st words differ - expected: '4', found: '-998244349'