結果

問題 No.2486 Don't come next to me
ユーザー LyricalMaestro
提出日時 2025-07-04 21:17:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 210 ms / 2,000 ms
コード長 706 bytes
コンパイル時間 419 ms
コンパイル使用メモリ 82,816 KB
実行使用メモリ 129,112 KB
最終ジャッジ日時 2025-07-04 21:17:09
合計ジャッジ時間 5,770 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/1724
       

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    array = []
    prev = A[0]
    for i in range(1, M):
        if A[i] - 1 - prev:
            array.append(A[i] - 1- prev)
        prev = A[i]
    
    memo = {}
    def dfs(n, memo):
        if n % 2 == 0:
            return n
        
        if n == 1:
            return 1
        
        if n in memo:
            return memo[n]
        
        m = n // 2
        ans = dfs(m, memo)
        memo[n] = ans * 2
        return ans * 2

    ans = 0
    for a in array:
        ans += dfs(a, memo)
    print(ans)











if __name__ == "__main__":
    main()
0