結果
| 問題 | 
                            No.1307 Rotate and Accumulate
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Wizist
                         | 
                    
| 提出日時 | 2020-12-04 14:56:29 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 829 bytes | 
| コンパイル時間 | 280 ms | 
| コンパイル使用メモリ | 81,792 KB | 
| 実行使用メモリ | 99,072 KB | 
| 最終ジャッジ日時 | 2024-09-15 01:16:42 | 
| 合計ジャッジ時間 | 7,675 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 1 WA * 4 TLE * 1 -- * 13 | 
ソースコード
#!/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)))
            
            
            
        
            
Wizist