結果
問題 | No.1096 Range Sums |
ユーザー |
|
提出日時 | 2022-10-20 13:32:19 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 165 ms / 2,000 ms |
コード長 | 1,169 bytes |
コンパイル時間 | 94 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 23,288 KB |
最終ジャッジ日時 | 2024-06-30 06:36:39 |
合計ジャッジ時間 | 1,918 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 27 ms
10,624 KB |
testcase_01 | AC | 27 ms
10,752 KB |
testcase_02 | AC | 29 ms
10,624 KB |
testcase_03 | AC | 27 ms
10,752 KB |
testcase_04 | AC | 25 ms
10,624 KB |
testcase_05 | AC | 26 ms
10,624 KB |
testcase_06 | AC | 26 ms
10,752 KB |
testcase_07 | AC | 28 ms
10,624 KB |
testcase_08 | AC | 30 ms
10,624 KB |
testcase_09 | AC | 30 ms
10,624 KB |
testcase_10 | AC | 165 ms
23,168 KB |
testcase_11 | AC | 156 ms
23,160 KB |
testcase_12 | AC | 156 ms
23,152 KB |
testcase_13 | AC | 154 ms
23,288 KB |
testcase_14 | AC | 149 ms
23,164 KB |
ソースコード
def accumulate_sum(start: int, end: int) -> int: if start > end: return 0 return (end * (end + 1) - start * (start - 1)) // 2 def main(): N = int(input()) A = list(map(int, input().split())) if N == 1: print(A[0]) return coefficients = [] if N % 2 == 0: for t in range(1, N//2 + 1): coefficients.append(2*(N//2 - t)*t + 2*accumulate_sum(1, t)) coeff_rev = reversed(coefficients) coefficients.extend(coeff_rev) else: for t in range(1, (N+1)//2): coefficients.append(t*(N - 2*(t-1)) + 2*accumulate_sum(1, t-1)) coeff_rev = reversed(coefficients) coefficients.append((N+1)//2 + 2*accumulate_sum(1, (N+1)//2 - 1)) coefficients.extend(coeff_rev) print(sum(A_elm * coeff for A_elm, coeff in zip(A, coefficients))) # Nが奇数 (N+1)//2=nとすると # 中央 n*1 + 2*sum(1, n-1) # 一つ横 (n-1)*3 + 2*sum(1, n-2) # 二つ横 (n-2)*5 + 2*sum(1,n-3) # Nが偶数 N//2=nとすると # 中央 # 中央2つ n*0 + 2*sum(1,n) # 一つ横 (n-1)*2 + 2*sum(1,n-1) if __name__ == "__main__": main()