답안 #549352

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
549352 2022-04-15T16:35:20 Z beaconmc Snowball (JOI21_ho_t2) PyPy 3
100 / 100
1326 ms 73052 KB
from bisect import *
n,q = map(int, input().split())
lis = list(map(int, input().split()))

diffs = []
for i in range(n-1):
    diffs.append(abs(lis[i] - lis[i+1]))
ans = [0 for i in range(n)]
queries = []
for i in range(q):
    queries.append(int(input()))


states = [[0,0,0]]

cur = [0,0,0]
pos = 0
for i in range(q):
    pos += queries[i]
    sus = False
    if pos<0 and cur[1]<abs(pos):
        sus = True
        cur[1] = abs(pos)
    elif pos>0 and cur[2] < pos:
        sus = True
        cur[2] = pos

    if sus:
        cur[0] = cur[1] + cur[2]
        states.append(list(cur))

states.sort()

for i in range(n-1):
    sus = bisect(states, [diffs[i]])

    if sus==len(states):
        ans[i+1] += states[-1][1]
        ans[i] += states[-1][2]
    else:
        if states[sus-1][1] == states[sus][1]:
            ans[i+1] += states[sus][1]
            ans[i] += diffs[i] - states[sus][1]
        else:
            ans[i] += states[sus][2]
            ans[i+1] += diffs[i] - states[sus][2]

ans[0] += states[-1][1]
ans[-1] += states[-1][2]

for i in ans:
    print(i)
        
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 22184 KB Output is correct
2 Correct 91 ms 22536 KB Output is correct
3 Correct 96 ms 22584 KB Output is correct
4 Correct 135 ms 26140 KB Output is correct
5 Correct 133 ms 26384 KB Output is correct
6 Correct 132 ms 26652 KB Output is correct
7 Correct 141 ms 26488 KB Output is correct
8 Correct 139 ms 26400 KB Output is correct
9 Correct 130 ms 26120 KB Output is correct
10 Correct 137 ms 26048 KB Output is correct
11 Correct 118 ms 25248 KB Output is correct
12 Correct 39 ms 18216 KB Output is correct
13 Correct 36 ms 18220 KB Output is correct
14 Correct 47 ms 18808 KB Output is correct
15 Correct 136 ms 26164 KB Output is correct
16 Correct 135 ms 26248 KB Output is correct
17 Correct 135 ms 26400 KB Output is correct
18 Correct 36 ms 18248 KB Output is correct
19 Correct 108 ms 25040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 22184 KB Output is correct
2 Correct 91 ms 22536 KB Output is correct
3 Correct 96 ms 22584 KB Output is correct
4 Correct 135 ms 26140 KB Output is correct
5 Correct 133 ms 26384 KB Output is correct
6 Correct 132 ms 26652 KB Output is correct
7 Correct 141 ms 26488 KB Output is correct
8 Correct 139 ms 26400 KB Output is correct
9 Correct 130 ms 26120 KB Output is correct
10 Correct 137 ms 26048 KB Output is correct
11 Correct 118 ms 25248 KB Output is correct
12 Correct 39 ms 18216 KB Output is correct
13 Correct 36 ms 18220 KB Output is correct
14 Correct 47 ms 18808 KB Output is correct
15 Correct 136 ms 26164 KB Output is correct
16 Correct 135 ms 26248 KB Output is correct
17 Correct 135 ms 26400 KB Output is correct
18 Correct 36 ms 18248 KB Output is correct
19 Correct 108 ms 25040 KB Output is correct
20 Correct 435 ms 51468 KB Output is correct
21 Correct 426 ms 48164 KB Output is correct
22 Correct 463 ms 48540 KB Output is correct
23 Correct 477 ms 50720 KB Output is correct
24 Correct 565 ms 52656 KB Output is correct
25 Correct 1326 ms 71748 KB Output is correct
26 Correct 1293 ms 72036 KB Output is correct
27 Correct 1271 ms 67876 KB Output is correct
28 Correct 1213 ms 63904 KB Output is correct
29 Correct 1044 ms 56236 KB Output is correct
30 Correct 724 ms 55108 KB Output is correct
31 Correct 550 ms 54536 KB Output is correct
32 Correct 479 ms 54184 KB Output is correct
33 Correct 230 ms 27828 KB Output is correct
34 Correct 786 ms 55112 KB Output is correct
35 Correct 864 ms 54072 KB Output is correct
36 Correct 1296 ms 67680 KB Output is correct
37 Correct 1168 ms 59324 KB Output is correct
38 Correct 1290 ms 68396 KB Output is correct
39 Correct 1068 ms 68032 KB Output is correct
40 Correct 982 ms 69076 KB Output is correct
41 Correct 412 ms 48208 KB Output is correct
42 Correct 459 ms 54340 KB Output is correct
43 Correct 960 ms 71944 KB Output is correct
44 Correct 419 ms 49016 KB Output is correct
45 Correct 921 ms 65980 KB Output is correct
46 Correct 994 ms 73052 KB Output is correct
47 Correct 881 ms 56028 KB Output is correct
48 Correct 990 ms 66420 KB Output is correct