結果

問題 No.2053 12345...
ユーザー ああいいああいい
提出日時 2022-08-21 17:15:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 606 bytes
コンパイル時間 401 ms
コンパイル使用メモリ 82,208 KB
実行使用メモリ 104,192 KB
最終ジャッジ日時 2024-04-18 13:04:35
合計ジャッジ時間 3,949 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,096 KB
testcase_01 AC 39 ms
51,968 KB
testcase_02 AC 42 ms
59,080 KB
testcase_03 AC 51 ms
68,864 KB
testcase_04 AC 77 ms
94,080 KB
testcase_05 AC 53 ms
66,688 KB
testcase_06 AC 73 ms
89,600 KB
testcase_07 AC 65 ms
80,768 KB
testcase_08 AC 59 ms
78,976 KB
testcase_09 AC 80 ms
93,440 KB
testcase_10 AC 93 ms
104,128 KB
testcase_11 AC 49 ms
65,920 KB
testcase_12 AC 53 ms
64,384 KB
testcase_13 AC 102 ms
104,192 KB
testcase_14 AC 59 ms
74,752 KB
testcase_15 AC 65 ms
76,800 KB
testcase_16 AC 60 ms
73,216 KB
testcase_17 AC 59 ms
69,120 KB
testcase_18 AC 104 ms
101,632 KB
testcase_19 AC 80 ms
95,872 KB
testcase_20 AC 56 ms
65,920 KB
testcase_21 AC 80 ms
83,456 KB
testcase_22 AC 45 ms
59,136 KB
testcase_23 AC 52 ms
63,616 KB
testcase_24 AC 53 ms
70,400 KB
testcase_25 AC 84 ms
102,272 KB
testcase_26 AC 59 ms
79,616 KB
testcase_27 AC 50 ms
70,528 KB
testcase_28 AC 47 ms
67,956 KB
testcase_29 AC 68 ms
86,784 KB
testcase_30 AC 53 ms
69,120 KB
testcase_31 AC 64 ms
86,144 KB
testcase_32 AC 94 ms
101,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int,input().split()))

ans = 0
left = 0
while left < N:
    right = left + 1
    if right < N and A[left] + 1 == A[right]:
        right += 1
        while right < N and A[right-1] + 1 == A[right]:
            right += 1
        tmp = right - left
        ans += tmp * (tmp - 1) // 2
        left = right
    elif right < N and A[left] - 1 == A[right]:
        right += 1
        while right < N and A[right - 1] - 1 == A[right]:
            right += 1
        tmp = right - left
        ans += tmp * (tmp - 1) // 2
        left = right
    else:
        left += 1
print(ans)
0