結果

問題 No.2053 12345...
ユーザー 👑 KazunKazun
提出日時 2022-08-25 19:31:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 499 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 108,792 KB
最終ジャッジ日時 2024-04-21 02:52:15
合計ジャッジ時間 4,166 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,224 KB
testcase_01 AC 36 ms
51,840 KB
testcase_02 AC 42 ms
59,520 KB
testcase_03 AC 50 ms
69,632 KB
testcase_04 AC 72 ms
93,568 KB
testcase_05 AC 46 ms
66,816 KB
testcase_06 AC 69 ms
90,624 KB
testcase_07 AC 58 ms
80,896 KB
testcase_08 AC 57 ms
78,464 KB
testcase_09 AC 70 ms
93,696 KB
testcase_10 AC 84 ms
105,600 KB
testcase_11 AC 50 ms
65,792 KB
testcase_12 AC 49 ms
67,200 KB
testcase_13 AC 99 ms
105,344 KB
testcase_14 AC 62 ms
83,200 KB
testcase_15 AC 58 ms
76,672 KB
testcase_16 AC 59 ms
78,848 KB
testcase_17 AC 55 ms
73,600 KB
testcase_18 AC 112 ms
108,792 KB
testcase_19 AC 86 ms
99,840 KB
testcase_20 AC 48 ms
65,408 KB
testcase_21 AC 83 ms
98,520 KB
testcase_22 AC 42 ms
59,136 KB
testcase_23 AC 46 ms
64,256 KB
testcase_24 AC 53 ms
71,680 KB
testcase_25 AC 83 ms
104,056 KB
testcase_26 AC 63 ms
80,768 KB
testcase_27 AC 54 ms
71,040 KB
testcase_28 AC 50 ms
68,864 KB
testcase_29 AC 68 ms
88,064 KB
testcase_30 AC 51 ms
69,760 KB
testcase_31 AC 67 ms
87,296 KB
testcase_32 AC 98 ms
102,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Run_Length_Encoding(S):
    """ランレングス圧縮

    S: 文字列
    """
    if not S:
        return []

    R=[[S[0],1]]

    for i in range(1,len(S)):
        if R[-1][0]==S[i]:
            R[-1][1]+=1
        else:
            R.append([S[i],1])

    return R

#==================================================
N=int(input())
A=list(map(int,input().split()))
B=[A[i+1]-A[i] for i in range(N-1)]

X=0
for d,k in Run_Length_Encoding(B):
    if d==1:
        X+=k*(k+1)//2

print(X)
0