File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const rl = require ( "readline" ) . createInterface ( { input : process . stdin } ) ;
2+ var iter = rl [ Symbol . asyncIterator ] ( ) ;
3+ const readline = async ( ) => ( await iter . next ( ) ) . value ;
4+
5+ void ( async function ( ) {
6+ const T = Number ( await readline ( ) ) ;
7+ for ( let i = 0 ; i < T ; i ++ ) {
8+ let [ n , m ] = ( await readline ( ) ) . split ( " " ) . map ( ( it ) => Number ( it ) ) ;
9+ let a ;
10+ let b ;
11+ if ( n > m ) {
12+ // 确保 a 比 b 长, n > m
13+ // [a,b] = (await readline()).split(' ')
14+ a = await readline ( ) ;
15+ b = await readline ( ) ;
16+ } else {
17+ [ n , m ] = [ m , n ] ;
18+ // [b,a] = (await readline()).split(' ')
19+ b = await readline ( ) ;
20+ a = await readline ( ) ;
21+ }
22+ const ans = new Array ( n ) . fill ( 1 ) ;
23+ for ( let i = 0 ; i < m ; i ++ ) {
24+ if ( a [ i + n - m ] === b [ i ] ) ans [ i + n - m ] = 0 ;
25+ }
26+ // let cur = 1
27+ // let ansNum = 0
28+ const BASE = 998244353n
29+ // 下面这种做法精度有问题因为 cur << 1 是 32 位
30+ // for(let i=0;i<n;++i){
31+ // if(ans[n-1-i]){
32+ // cur = (cur+BASE)%BASE
33+ // ansNum = (ansNum+cur+BASE)%BASE
34+ // }
35+ // cur = cur << 1
36+ // // console.log(cur)
37+ // }
38+ // console.log(ansNum)
39+
40+ // 转成 BigInt
41+ const binStr = ans . join ( "" ) ;
42+ const result = BigInt ( "0b" + binStr ) % BASE ;
43+
44+ console . log ( result . toString ( ) ) ;
45+ }
46+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments