結果

問題 No.1307 Rotate and Accumulate
ユーザー WizistWizist
提出日時 2020-12-04 14:56:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 829 bytes
コンパイル時間 503 ms
コンパイル使用メモリ 86,968 KB
実行使用メモリ 98,608 KB
最終ジャッジ日時 2023-10-13 03:36:50
合計ジャッジ時間 8,379 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
75,720 KB
testcase_01 AC 72 ms
71,272 KB
testcase_02 AC 71 ms
71,372 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 73 ms
71,428 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
#
# No.1307 Rotate and Accumulate
#
import sys, os, math

def read_ints(): return list(map(int, input().split()))

n, q = read_ints()
a, r = read_ints(), sorted(read_ints())
c = [0] * (2 * n + 1)
for i in range(1, 2 * n + 1):
	c[i] = a[(i - 1) % n] + c[i - 1]
b = [0] * n

s = []; m = 0
for x in r:
	if not s:
		s.append(x); m += 1
	elif x == s[-1]:
		m += 1
	elif x == s[-1] + 1:
		if m > 1:
			for i in range(n):
				b[i] += a[(i + s[-1]) % n] * (m - 1)
			m = 1
		s.append(x)
	else:
		if m > 1:
			for i in range(n):
				b[i] += a[(i + s[-1]) % n] * m
		else:
			for i in range(n):
				b[i] += c[i + s[-1] + 1] - c[i + s[0]]
		s = [x]; m = 1

if m > 1:
	for i in range(n):
		b[i] += a[(i + s[-1]) % n] * m
else:
	for i in range(n):
		b[i] += c[i + s[-1] + 1] - c[i + s[0]]

print(" ".join(map(str, b)))
0