Submission #57291977


Source Code Expand

from math import inf

n = int(input())
a = [int(i) for i in input().split()]

cnt, d, ans = 0, inf, n
for i in range(n):
	if i == 0 or a[i] - a[i - 1] == d:
		d = a[i] if i == 0 else a[i] - a[i - 1]
		cnt += 1
		continue
	
	ans += cnt * (cnt + 1) // 2 - cnt
	cnt = 2
	d = a[i] - a[i - 1]
ans += cnt * (cnt + 1) // 2 - cnt

print(ans)

Submission Info

Submission Time
Task C - Count Arithmetic Subarrays
User c1ampy
Language Python (CPython 3.11.4)
Score 300
Code Size 352 Byte
Status AC
Exec Time 105 ms
Memory 31548 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 21
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 02_random2_10.txt, 03_handmade_00.txt, 03_handmade_01.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 10 ms 8776 KiB
00_sample_01.txt AC 10 ms 8692 KiB
00_sample_02.txt AC 10 ms 8692 KiB
01_random_00.txt AC 10 ms 8700 KiB
01_random_01.txt AC 10 ms 8716 KiB
01_random_02.txt AC 53 ms 18780 KiB
01_random_03.txt AC 71 ms 23244 KiB
01_random_04.txt AC 60 ms 20928 KiB
02_random2_00.txt AC 92 ms 30736 KiB
02_random2_01.txt AC 93 ms 30708 KiB
02_random2_02.txt AC 92 ms 30708 KiB
02_random2_03.txt AC 95 ms 30684 KiB
02_random2_04.txt AC 98 ms 30736 KiB
02_random2_05.txt AC 95 ms 31248 KiB
02_random2_06.txt AC 100 ms 31200 KiB
02_random2_07.txt AC 102 ms 31452 KiB
02_random2_08.txt AC 102 ms 30812 KiB
02_random2_09.txt AC 102 ms 31200 KiB
02_random2_10.txt AC 105 ms 30612 KiB
03_handmade_00.txt AC 11 ms 8728 KiB
03_handmade_01.txt AC 98 ms 31548 KiB