QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#26078 | #2551. Math String | Mr_Eight | AC ✓ | 3ms | 3752kb | C++14 | 4.0kb | 2022-04-06 10:36:50 | 2022-04-29 02:53:04 |
Judging History
answer
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <functional>
#include <cstring>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <complex>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define itn int
#define nit int
#define ll long long
#define ms multiset
#define F(i,a,b) for(register int i=a,i##end=b;i<=i##end;++i)
#define UF(i,a,b) for(register int i=a,i##end=b;i>=i##end;--i)
#define re register
#define ri re int
#define il inline
#define pii pair<int,int>
#define cp complex<double>
//#pra gma G CC opti mize(3)
using namespace std;
using std::bitset;
//using namespace __gnu_pbds;
const double Pi=acos(-1);
namespace fastIO {
template<class T>
inline void read(T &x) {
x=0;
bool fu=0;
char ch=0;
while(ch>'9'||ch<'0') {
ch=getchar();
if(ch=='-')fu=1;
}
while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar();
if(fu)x=-x;
}
inline int read() {
int x=0;
bool fu=0;
char ch=0;
while(ch>'9'||ch<'0') {
ch=getchar();
if(ch=='-')fu=1;
}
while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar();
return fu?-x:x;
}
char _n_u_m_[40];
template<class T>
inline void write(T x ) {
if(x==0){
putchar('0');
return;
}
T tmp = x > 0 ? x : -x ;
if( x < 0 ) putchar('-') ;
register int cnt = 0 ;
while( tmp > 0 ) {
_n_u_m_[ cnt ++ ] = tmp % 10 + '0' ;
tmp /= 10 ;
}
while( cnt > 0 ) putchar(_n_u_m_[ -- cnt ]) ;
}
template<class T>
inline void write(T x ,char ch) {
write(x);
putchar(ch);
}
}
using namespace fastIO;
#define mod 998244353
template<int N,int M>
struct mat {
long long v[N+1][M+1];
mat() {
memset(v,0,sizeof(v));
}
long long & operator()(register int xpos,register int ypos) {
return v[xpos][ypos];
}
long long * operator[](register int xpos) {
return v[xpos];
}
inline int Nsize() {
return N;
} inline int Msize() {
return M;
}
};
template<int N,int M,int K>
inline mat<N,K> operator*(mat<N,M> a,mat<M,K> b) {
mat<N,K>rt;
for(register int i=1; i<=N; i++) {
for(register int j=1; j<=K; j++) {
for(register int k=1; k<=M; k++) {
rt.v[i][j]+=a.v[i][k]*b.v[k][j];
#ifdef mod
rt.v[i][j]%=mod;
#else
#warning mod is not defined
#endif
}
}
}
return rt;
}
template<int N,int M>
inline mat<N,M> operator*(mat<N,M> a,long long x) {
mat<N,M>rt;
for(register int i=1; i<=N; i++) {
for(register int j=1; j<=M; j++) {
#ifdef mod
rt.v[i][j]=a.v[i][j]*x%mod;
#else
rt.v[i][j]=a.v[i][j]*x;
#endif
}
}return rt;
}
template<int N,int M>
inline mat<N,M> operator+(mat<N,M> a,mat<N,M> b) {
mat<N,M>rt;
for(register int i=1; i<=N; i++) {
for(register int j=1; j<=M; j++) {
#ifdef mod
rt.v[i][j]=((a.v[i][j]+b.v[i][j]<mod)?(a.v[i][j]+b.v[i][j]):(a.v[i][j]+b.v[i][j]-mod));
#else
rt.v[i][j]=a.v[i][j]+b.v[i][j];
#endif
}
}return rt;
}
template<int N>
inline mat<N,N> pw(mat<N,N> bot,long long p) {
mat<N,N>rt;
F(i,1,N)rt.v[i][i]=1;
while(p) {
if(p&1) {
rt=rt*bot;
}
bot=bot*bot,p>>=1;
}
return rt;
}
struct S{
mat<4,4> a,b,c,d;
};
inline S operator*(S x,S y){
return {x.a*y.a+x.b*y.c,x.a*y.b+x.b*y.d,x.c*y.a+x.d*y.c,x.c*y.b+x.d*y.d};
}
inline S pw(S bot,long long p) {
S rt;
F(i,1,4)rt.a[i][i]=rt.d[i][i]=1;
// F(i,1,p)rt=rt*bot;
// return rt;
while(p) {
if(p&1) {
rt=rt*bot;
}
bot=bot*bot,p>>=1;
}
return rt;
}
mat<4,4>base,T1,T2,T3;
S B,TB;
int main() {//1,082,565 101331
base[1][2]=45,base[1][3]=9,base[1][4]=9;
T1[1][1]=T1[3][3]=T1[4][4]=9,T1[2][2]=90,T1[3][2]=45;
T2[1][1]=T2[2][1]=T2[4][3]=T2[4][4]=1;
T3[1][1]=T3[2][3]=T3[4][4]=1;
B.a=base;
TB.a=TB.c=T1,TB.b=T2+T3;
ll n;cin>>n;
B=B*pw(TB,n-1);
cout<<(B.a[1][1]+B.a[1][2])%mod;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 3572kb
input:
1
output:
45
result:
ok answer is '45'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3620kb
input:
3
output:
407430
result:
ok answer is '407430'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
1000000000000000000
output:
493565653
result:
ok answer is '493565653'
Test #4:
score: 0
Accepted
time: 3ms
memory: 3624kb
input:
999999999999999254
output:
963821656
result:
ok answer is '963821656'
Test #5:
score: 0
Accepted
time: 3ms
memory: 3620kb
input:
2
output:
4455
result:
ok answer is '4455'
Test #6:
score: 0
Accepted
time: 3ms
memory: 3600kb
input:
999999999999999062
output:
256461144
result:
ok answer is '256461144'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3652kb
input:
4
output:
36934785
result:
ok answer is '36934785'
Test #8:
score: 0
Accepted
time: 3ms
memory: 3744kb
input:
5
output:
350210541
result:
ok answer is '350210541'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3552kb
input:
6
output:
427185456
result:
ok answer is '427185456'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3480kb
input:
7
output:
991901155
result:
ok answer is '991901155'
Test #11:
score: 0
Accepted
time: 3ms
memory: 3552kb
input:
8
output:
110899952
result:
ok answer is '110899952'
Test #12:
score: 0
Accepted
time: 3ms
memory: 3600kb
input:
9
output:
89411672
result:
ok answer is '89411672'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
10
output:
401287887
result:
ok answer is '401287887'
Test #14:
score: 0
Accepted
time: 3ms
memory: 3480kb
input:
172
output:
376377812
result:
ok answer is '376377812'
Test #15:
score: 0
Accepted
time: 3ms
memory: 3616kb
input:
238
output:
81946973
result:
ok answer is '81946973'
Test #16:
score: 0
Accepted
time: 3ms
memory: 3480kb
input:
730
output:
661959857
result:
ok answer is '661959857'
Test #17:
score: 0
Accepted
time: 1ms
memory: 3680kb
input:
684
output:
828317367
result:
ok answer is '828317367'
Test #18:
score: 0
Accepted
time: 3ms
memory: 3696kb
input:
633
output:
673539741
result:
ok answer is '673539741'
Test #19:
score: 0
Accepted
time: 3ms
memory: 3596kb
input:
897
output:
159321465
result:
ok answer is '159321465'
Test #20:
score: 0
Accepted
time: 2ms
memory: 3684kb
input:
809
output:
521464595
result:
ok answer is '521464595'
Test #21:
score: 0
Accepted
time: 2ms
memory: 3592kb
input:
302
output:
92391482
result:
ok answer is '92391482'
Test #22:
score: 0
Accepted
time: 1ms
memory: 3480kb
input:
261
output:
854903269
result:
ok answer is '854903269'
Test #23:
score: 0
Accepted
time: 3ms
memory: 3480kb
input:
497
output:
594207939
result:
ok answer is '594207939'
Test #24:
score: 0
Accepted
time: 3ms
memory: 3480kb
input:
951
output:
927809758
result:
ok answer is '927809758'
Test #25:
score: 0
Accepted
time: 3ms
memory: 3616kb
input:
980
output:
65372821
result:
ok answer is '65372821'
Test #26:
score: 0
Accepted
time: 3ms
memory: 3592kb
input:
1000
output:
971150090
result:
ok answer is '971150090'
Test #27:
score: 0
Accepted
time: 3ms
memory: 3700kb
input:
969
output:
511011493
result:
ok answer is '511011493'
Test #28:
score: 0
Accepted
time: 1ms
memory: 3600kb
input:
998
output:
549357456
result:
ok answer is '549357456'
Test #29:
score: 0
Accepted
time: 1ms
memory: 3596kb
input:
98558
output:
245733611
result:
ok answer is '245733611'
Test #30:
score: 0
Accepted
time: 3ms
memory: 3568kb
input:
35873
output:
524107440
result:
ok answer is '524107440'
Test #31:
score: 0
Accepted
time: 1ms
memory: 3596kb
input:
3015
output:
928761172
result:
ok answer is '928761172'
Test #32:
score: 0
Accepted
time: 3ms
memory: 3688kb
input:
44398
output:
339084928
result:
ok answer is '339084928'
Test #33:
score: 0
Accepted
time: 3ms
memory: 3752kb
input:
82497
output:
273305194
result:
ok answer is '273305194'
Test #34:
score: 0
Accepted
time: 3ms
memory: 3748kb
input:
81678
output:
423439974
result:
ok answer is '423439974'
Test #35:
score: 0
Accepted
time: 3ms
memory: 3624kb
input:
95002
output:
868411966
result:
ok answer is '868411966'
Test #36:
score: 0
Accepted
time: 3ms
memory: 3620kb
input:
56392
output:
127537737
result:
ok answer is '127537737'
Test #37:
score: 0
Accepted
time: 3ms
memory: 3616kb
input:
49489
output:
841113901
result:
ok answer is '841113901'
Test #38:
score: 0
Accepted
time: 3ms
memory: 3588kb
input:
57109
output:
808819191
result:
ok answer is '808819191'
Test #39:
score: 0
Accepted
time: 3ms
memory: 3596kb
input:
99674
output:
890052301
result:
ok answer is '890052301'
Test #40:
score: 0
Accepted
time: 3ms
memory: 3600kb
input:
99513
output:
147223708
result:
ok answer is '147223708'
Test #41:
score: 0
Accepted
time: 2ms
memory: 3484kb
input:
99950
output:
638000302
result:
ok answer is '638000302'
Test #42:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
99939
output:
627100241
result:
ok answer is '627100241'
Test #43:
score: 0
Accepted
time: 1ms
memory: 3596kb
input:
99904
output:
768803875
result:
ok answer is '768803875'
Test #44:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
822981260158560519
output:
500129705
result:
ok answer is '500129705'
Test #45:
score: 0
Accepted
time: 3ms
memory: 3548kb
input:
28316250878314571
output:
954707612
result:
ok answer is '954707612'
Test #46:
score: 0
Accepted
time: 3ms
memory: 3624kb
input:
779547116602636424
output:
349022088
result:
ok answer is '349022088'
Test #47:
score: 0
Accepted
time: 2ms
memory: 3748kb
input:
578223540025879436
output:
310507001
result:
ok answer is '310507001'
Test #48:
score: 0
Accepted
time: 3ms
memory: 3676kb
input:
335408917862248766
output:
399860005
result:
ok answer is '399860005'
Test #49:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
74859962623990078
output:
905924996
result:
ok answer is '905924996'
Test #50:
score: 0
Accepted
time: 3ms
memory: 3708kb
input:
252509054434733439
output:
57677315
result:
ok answer is '57677315'
Test #51:
score: 0
Accepted
time: 2ms
memory: 3596kb
input:
760713016476890622
output:
840620988
result:
ok answer is '840620988'
Test #52:
score: 0
Accepted
time: 3ms
memory: 3696kb
input:
919845426262803496
output:
929606336
result:
ok answer is '929606336'
Test #53:
score: 0
Accepted
time: 3ms
memory: 3596kb
input:
585335723211847194
output:
975973040
result:
ok answer is '975973040'
Test #54:
score: 0
Accepted
time: 1ms
memory: 3688kb
input:
999999999999999478
output:
859690282
result:
ok answer is '859690282'
Test #55:
score: 0
Accepted
time: 3ms
memory: 3548kb
input:
999999999999999902
output:
879587490
result:
ok answer is '879587490'
Test #56:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
999999999999999168
output:
585232180
result:
ok answer is '585232180'