QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#764913 | #9479. And DNA | ReqCxmChtChr | AC ✓ | 2ms | 3956kb | C++14 | 3.5kb | 2024-11-20 11:09:31 | 2024-11-20 11:09:37 |
Judging History
answer
#include<bits/stdc++.h>
//#pragma GCC optimize(3)
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define ll long long
#define ull unsigned ll
#define db double
#define ldb long db
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pbI push_back
#define inf 1e9
#define mdI int mid=(l+r)>>1
#define lowbit(x) (x&-x)
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define MAXN 520
#define gint __int128
#define MOD 998244353
int qread(){
char o=getchar();int f=1,x=0;
for(;!isdigit(o);o=getchar())if(o=='-')f*=-1;
for(;isdigit(o);o=getchar())x=x*10+o-'0';
return f*x;
}
void chmx(int &x,int y){if(y>x)x=y;}
void chmi(int &x,int y){if(y<x)x=y;}
bool FLA;
namespace MathPart{
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define vep(a,b,c) for(int a=b;a>=c;a--)
void exgcd(ll a,ll b,ll &x,ll &y){if(b==0){x=1,y=0;return;}exgcd(b,a%b,y,x);y-=(a/b)*x;}
ll inv(ll a,ll p=MOD){ll x,y;exgcd(a,p,x,y);return (x+p)%p;}
gint qp(ll a,ll b,ll p=MOD){gint rs=1,bs=a;while(b){if(b&1){rs=rs*bs%p;}bs=bs*bs%p;b>>=1;}return rs;}
ll fac[MAXN],ifac[MAXN];
void initF(ll n,ll p=MOD){
fac[0]=1;rep(i,1,n){fac[i]=fac[i-1]*i%p;}
ifac[n]=inv(fac[n],p);vep(i,n-1,0){ifac[i]=ifac[i+1]*(i+1)%p;}
}
ll C(ll n,ll m){if(n<m){return 0;}return fac[n]*ifac[m]%MOD*ifac[n-m]%MOD;}
ll CC(ll n,ll m,ll p=MOD){ll rs=1;rep(i,0,m-1){rs=rs*(n-i)%p*inv(i+1,MOD)%p;}return rs;}
ll S2OL(ll n,ll m){
ll rs=0,d=1,f=1;
for(ll k=0;k<=m;k++){
rs=(rs+f*C(m,k)*qp(m-k,n,MOD)%MOD+MOD)%MOD;
d=d*max(k,1ll)%MOD;f*=-1;
}return rs*inv(d,MOD)%MOD;
}
ll phi(ll a){ll rs=a,m=sqrt(a);
rep(i,2,m){if(a%i==0){rs=rs/i*(i-1);while(a%i==0){a/=i;}}}
if(a>1){rs=rs/a*(a-1);}return rs;
}
bool MR(ll pr){if(pr<2)return 0;if(pr==3)return 1;if(pr==2)return 1;
ll a=pr-1,b=0;while(!(a&1))a>>=1,b++;
for(int i=1;i<=8;++i){
ll x=rand()%(pr-2)+2,v=qp(x,a,pr),j;if(v==1||v==pr-1)continue;
for(j=0;j<b-1;j++){v=(gint)v*v%pr;if(v==pr-1)break;}
if(v!=pr-1)return 0;
}return 1;
}
}
//using namespace MathPart;
int n,m,Pre;
int get(int m){
if(m==1){return Pre;}
if(m==0){return 1;}
if(m&1){return (get(1)*get(m/2))%MOD;}
else{return (get(m/2-1)+get(m/2))%MOD;}
}
struct Mat{
int a[4][4];
Mat(){memset(a,0,sizeof(a));}
void one(){rep(i,0,3)a[i][i]=1;}
Mat operator*(const Mat&b)const{
Mat c;
rep(k,0,3){rep(i,0,3){rep(j,0,3){
c.a[i][j]=(c.a[i][j]+a[i][k]*b.a[k][j]%MOD)%MOD;
}}}
return c;
}
Mat operator=(Mat b){
rep(i,0,3){rep(j,0,3){a[i][j]=b.a[i][j];}}
return *this;
}
}Pri,rs,bs;
bool FLB;
signed main(){
cerr<<((&FLB)-(&FLA))/1024.0/1024<<endl;
cin>>n>>m;
Pri.a[1][2]=Pri.a[1][3]=Pri.a[3][2]=Pri.a[2][1]=1;
int b=n;
rs.one();bs=Pri;
while(b){
if(b&1){rs=rs*bs;}
bs=bs*bs;b>>=1;
}
rep(i,0,3){Pre=(Pre+rs.a[i][i])%MOD;}
cout<<get(m);
}
/*
*从小m考虑 m=1时01->10/11 11->10 10->01
m从低位开始,m奇->最低位不应有进位,最低一位独立,
m偶,如果偏要产生进位,应有三个1,但是可以由三个1扩展得知应当每一个都是1,实际上如果出现一个1,都应该全部为1
选择同奇,可以整体减一(化解进位问题)。
把所有的性质放在脑子里,随机应变
分段调试
不要执着于考虑环能带来什么性质,照常分析即可.(自信最重要)
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3892kb
input:
3 2
output:
4
result:
ok "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
3 0
output:
1
result:
ok "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3956kb
input:
100 100
output:
343406454
result:
ok "343406454"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
686579306 119540831
output:
260602195
result:
ok "260602195"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3888kb
input:
26855095 796233790
output:
492736984
result:
ok "492736984"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3880kb
input:
295310488 262950628
output:
503008241
result:
ok "503008241"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3864kb
input:
239670714 149827706
output:
994702969
result:
ok "994702969"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
790779949 110053353
output:
898252188
result:
ok "898252188"
Test #9:
score: 0
Accepted
time: 2ms
memory: 3876kb
input:
726600542 795285932
output:
183726777
result:
ok "183726777"
Test #10:
score: 0
Accepted
time: 1ms
memory: 3944kb
input:
957970519 585582861
output:
298814018
result:
ok "298814018"
Test #11:
score: 0
Accepted
time: 2ms
memory: 3876kb
input:
93349859 634036506
output:
110693443
result:
ok "110693443"
Test #12:
score: 0
Accepted
time: 1ms
memory: 3944kb
input:
453035113 34126396
output:
306244220
result:
ok "306244220"
Test #13:
score: 0
Accepted
time: 1ms
memory: 3868kb
input:
31994526 100604502
output:
930620701
result:
ok "930620701"
Test #14:
score: 0
Accepted
time: 1ms
memory: 3860kb
input:
234760741 249817734
output:
440195858
result:
ok "440195858"
Test #15:
score: 0
Accepted
time: 1ms
memory: 3748kb
input:
542621111 646412689
output:
207377992
result:
ok "207377992"
Test #16:
score: 0
Accepted
time: 1ms
memory: 3816kb
input:
28492783 602632297
output:
65234506
result:
ok "65234506"
Test #17:
score: 0
Accepted
time: 1ms
memory: 3740kb
input:
213500301 768820204
output:
540205113
result:
ok "540205113"
Test #18:
score: 0
Accepted
time: 1ms
memory: 3796kb
input:
697808101 753041955
output:
93561295
result:
ok "93561295"
Test #19:
score: 0
Accepted
time: 2ms
memory: 3808kb
input:
585126464 450455977
output:
91109717
result:
ok "91109717"
Test #20:
score: 0
Accepted
time: 1ms
memory: 3800kb
input:
236696315 482334538
output:
925575199
result:
ok "925575199"
Test #21:
score: 0
Accepted
time: 1ms
memory: 3896kb
input:
632719214 298704996
output:
358926097
result:
ok "358926097"
Test #22:
score: 0
Accepted
time: 2ms
memory: 3872kb
input:
869119333 933404114
output:
318501108
result:
ok "318501108"
Test #23:
score: 0
Accepted
time: 1ms
memory: 3864kb
input:
6977994 814763202
output:
585332987
result:
ok "585332987"
Test #24:
score: 0
Accepted
time: 0ms
memory: 3884kb
input:
3 1
output:
3
result:
ok "3"
Test #25:
score: 0
Accepted
time: 1ms
memory: 3808kb
input:
3 1000000000
output:
279679226
result:
ok "279679226"
Test #26:
score: 0
Accepted
time: 0ms
memory: 3884kb
input:
4 0
output:
1
result:
ok "1"
Test #27:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
4 1
output:
2
result:
ok "2"
Test #28:
score: 0
Accepted
time: 1ms
memory: 3816kb
input:
4 1000000000
output:
1755648
result:
ok "1755648"
Test #29:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
1000000000 0
output:
1
result:
ok "1"
Test #30:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
1000000000 1
output:
696798313
result:
ok "696798313"
Test #31:
score: 0
Accepted
time: 1ms
memory: 3860kb
input:
1000000000 1000000000
output:
703786301
result:
ok "703786301"
Extra Test:
score: 0
Extra Test Passed