結果

問題 No.2060 AND Sequence
ユーザー taiga0629kyoprotaiga0629kyopro
提出日時 2022-08-06 01:45:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 1,104 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 81,756 KB
実行使用メモリ 77,828 KB
最終ジャッジ日時 2023-10-19 05:55:17
合計ジャッジ時間 5,404 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
56,116 KB
testcase_01 AC 49 ms
59,352 KB
testcase_02 AC 105 ms
77,052 KB
testcase_03 AC 48 ms
61,400 KB
testcase_04 AC 48 ms
61,400 KB
testcase_05 AC 46 ms
59,352 KB
testcase_06 AC 47 ms
61,400 KB
testcase_07 AC 52 ms
61,400 KB
testcase_08 AC 48 ms
61,400 KB
testcase_09 AC 48 ms
61,400 KB
testcase_10 AC 48 ms
61,400 KB
testcase_11 AC 47 ms
61,400 KB
testcase_12 AC 48 ms
61,400 KB
testcase_13 AC 43 ms
54,072 KB
testcase_14 AC 98 ms
77,300 KB
testcase_15 AC 95 ms
77,028 KB
testcase_16 AC 95 ms
77,828 KB
testcase_17 AC 101 ms
77,240 KB
testcase_18 AC 94 ms
77,068 KB
testcase_19 AC 99 ms
77,488 KB
testcase_20 AC 95 ms
77,068 KB
testcase_21 AC 99 ms
77,504 KB
testcase_22 AC 89 ms
76,772 KB
testcase_23 AC 75 ms
74,028 KB
testcase_24 AC 83 ms
76,776 KB
testcase_25 AC 101 ms
77,332 KB
testcase_26 AC 94 ms
77,068 KB
testcase_27 AC 96 ms
77,068 KB
testcase_28 AC 85 ms
76,856 KB
testcase_29 AC 102 ms
77,592 KB
testcase_30 AC 96 ms
77,068 KB
testcase_31 AC 101 ms
77,068 KB
testcase_32 AC 101 ms
77,480 KB
testcase_33 AC 106 ms
77,372 KB
testcase_34 AC 87 ms
77,068 KB
testcase_35 AC 115 ms
77,780 KB
testcase_36 AC 97 ms
77,068 KB
testcase_37 AC 97 ms
77,308 KB
testcase_38 AC 106 ms
77,756 KB
testcase_39 AC 97 ms
77,064 KB
testcase_40 AC 84 ms
76,852 KB
testcase_41 AC 89 ms
76,868 KB
testcase_42 AC 101 ms
77,296 KB
testcase_43 AC 103 ms
77,056 KB
testcase_44 AC 63 ms
71,048 KB
testcase_45 AC 84 ms
77,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def naive (n,m):
    mod=998244353
    dp=[[0]*(m+1) for i in range(n+1)]
    dp[0][0]=1
    for i in range(1,n+1):
        for x in range(m+1):
            for y in range(m+1):
                if x&y==y:
                    dp[i][x]+=dp[i-1][y]
                    dp[i][x]%=mod
    return sum(dp[n])%mod

def sol1(n,m):
    mod=998244353
    memo=dict()
    def dp(m,k,f):
        if m==0:
            if k==0 and f==1:return 1
            return 0
        if (m,k,f) in memo:return memo[m,k,f]
        ans=0
        for bx in range(2):
            nf=f
            if nf==0 and m%2==1 and bx==0:nf=1
            if nf==1 and m%2==0 and bx==1:nf=0
            ans+=dp(m//2,k-bx,nf)
            ans%=mod
        memo[m,k,f]=ans
        return ans
    ans=0
    for k in range(33):
        ans+=dp(m,k,1)*pow(n,k,mod)%mod
        ans%=mod
    return ans

from random import randrange as rd
cnt=0
while 0:
    cnt+=1
    print(cnt)
    n=rd(2,1000)
    m=rd(1,1000)
    ans1=naive(n,m)
    ans2=sol1(n,m)
    if ans1!=ans2:
        print(n,m)
        break

n,m=map(int,input().split())
print(sol1(n,m))
0