Submission #659586

# Submission time Handle Problem Language Result Execution time Memory
659586 2022-11-18T15:46:23 Z beaconmc Fancy Fence (CEOI20_fancyfence) PyPy 3
100 / 100
170 ms 44284 KB
n = int(input())
h = list(map(int, input().split()))
w = list(map(int, input().split()))


sussies = [list(i) for i in zip(h,w)]
stack = []

def rect(a,b):
    return a*(a+1)*b*(b+1)//4

def comb():
    if len(stack)>1 and stack[-1][0] == stack[-2][0]:
        a = stack.pop()[1]
        stack[-1][1] += a

ans = 0
for i in sussies:
    if not stack:
        stack.append(i)
    else:
        while stack[-1][0] > i[0]:
            
            if len(stack)==1:
                ans += rect(stack[-1][0],stack[-1][1])-rect(i[0],stack[-1][1])
                stack[-1][0] = i[0]
            else:
                sus = max(stack[-2][0], i[0])
                ans += rect(stack[-1][0],stack[-1][1])-rect(sus,stack[-1][1])
                stack[-1][0] = sus
                comb()
        stack.append(i)
        comb()

while len(stack) != 1:
    sus = stack[-2][0]
    ans += rect(stack[-1][0],stack[-1][1])-rect(sus,stack[-1][1])
    stack[-1][0] = sus
    comb()

ans += rect(stack[0][0], stack[0][1])

print(ans%1000000007)
                
# Verdict Execution time Memory Grader output
1 Correct 36 ms 18220 KB Output is correct
2 Correct 50 ms 19220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 18208 KB Output is correct
2 Correct 34 ms 18180 KB Output is correct
3 Correct 35 ms 18148 KB Output is correct
4 Correct 33 ms 18220 KB Output is correct
5 Correct 35 ms 18112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 18220 KB Output is correct
2 Correct 42 ms 19028 KB Output is correct
3 Correct 110 ms 31424 KB Output is correct
4 Correct 127 ms 36212 KB Output is correct
5 Correct 135 ms 37432 KB Output is correct
6 Correct 121 ms 36080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 18944 KB Output is correct
2 Correct 51 ms 22280 KB Output is correct
3 Correct 73 ms 29624 KB Output is correct
4 Correct 115 ms 37548 KB Output is correct
5 Correct 107 ms 37544 KB Output is correct
6 Correct 34 ms 18228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 18220 KB Output is correct
2 Correct 40 ms 18944 KB Output is correct
3 Correct 57 ms 22484 KB Output is correct
4 Correct 75 ms 30476 KB Output is correct
5 Correct 107 ms 39472 KB Output is correct
6 Correct 106 ms 39660 KB Output is correct
7 Correct 47 ms 19136 KB Output is correct
8 Correct 65 ms 23576 KB Output is correct
9 Correct 95 ms 31020 KB Output is correct
10 Correct 148 ms 43176 KB Output is correct
11 Correct 144 ms 44284 KB Output is correct
12 Correct 34 ms 18228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 18252 KB Output is correct
2 Correct 51 ms 19180 KB Output is correct
3 Correct 34 ms 18196 KB Output is correct
4 Correct 34 ms 18132 KB Output is correct
5 Correct 33 ms 18228 KB Output is correct
6 Correct 35 ms 18236 KB Output is correct
7 Correct 34 ms 18220 KB Output is correct
8 Correct 45 ms 19040 KB Output is correct
9 Correct 42 ms 19032 KB Output is correct
10 Correct 46 ms 19136 KB Output is correct
11 Correct 34 ms 18228 KB Output is correct
12 Correct 39 ms 18324 KB Output is correct
13 Correct 49 ms 19284 KB Output is correct
14 Correct 46 ms 19124 KB Output is correct
15 Correct 47 ms 19332 KB Output is correct
16 Correct 35 ms 18228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 18220 KB Output is correct
2 Correct 50 ms 19220 KB Output is correct
3 Correct 36 ms 18184 KB Output is correct
4 Correct 48 ms 19224 KB Output is correct
5 Correct 36 ms 18320 KB Output is correct
6 Correct 35 ms 18156 KB Output is correct
7 Correct 34 ms 18236 KB Output is correct
8 Correct 35 ms 18224 KB Output is correct
9 Correct 37 ms 18204 KB Output is correct
10 Correct 41 ms 18988 KB Output is correct
11 Correct 102 ms 31276 KB Output is correct
12 Correct 125 ms 36156 KB Output is correct
13 Correct 132 ms 37436 KB Output is correct
14 Correct 124 ms 36012 KB Output is correct
15 Correct 40 ms 19028 KB Output is correct
16 Correct 55 ms 22528 KB Output is correct
17 Correct 73 ms 30500 KB Output is correct
18 Correct 105 ms 39644 KB Output is correct
19 Correct 102 ms 39652 KB Output is correct
20 Correct 52 ms 19020 KB Output is correct
21 Correct 63 ms 23548 KB Output is correct
22 Correct 98 ms 31140 KB Output is correct
23 Correct 148 ms 43292 KB Output is correct
24 Correct 139 ms 43404 KB Output is correct
25 Correct 37 ms 18188 KB Output is correct
26 Correct 39 ms 18284 KB Output is correct
27 Correct 48 ms 19304 KB Output is correct
28 Correct 47 ms 19136 KB Output is correct
29 Correct 51 ms 19336 KB Output is correct
30 Correct 91 ms 24652 KB Output is correct
31 Correct 87 ms 26216 KB Output is correct
32 Correct 119 ms 31188 KB Output is correct
33 Correct 119 ms 30696 KB Output is correct
34 Correct 167 ms 42540 KB Output is correct
35 Correct 159 ms 42452 KB Output is correct
36 Correct 167 ms 39376 KB Output is correct
37 Correct 158 ms 39736 KB Output is correct
38 Correct 38 ms 18212 KB Output is correct
39 Correct 165 ms 39616 KB Output is correct
40 Correct 157 ms 39668 KB Output is correct
41 Correct 170 ms 39656 KB Output is correct
42 Correct 156 ms 39692 KB Output is correct