Submission #1230728


Source Code Expand

n = gets.to_i
b = Array.new(n + 1)
gets.split.each_with_index{|s,idx|b[s.to_i] = idx + 1}
c = Array.new(n + 1, 0)
1.upto(n){|i|c[i] = n - i + 1}
ans = 0
1.upto(n){|idx|
	v=b[idx]
	cv=c[v]
	j=v-1
	while c[j]>0
		c[j]-=cv
		j-=1
	end
	ans+=idx*cv*(v-j)
	c[v]=0
}

puts ans

Submission Info

Submission Time
Task B - Minimum Sum
User urutom
Language Ruby (2.3.3)
Score 0
Code Size 288 Byte
Status TLE
Exec Time 2109 ms
Memory 16780 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 11
TLE × 2
Set Name Test Cases
Sample example0, example1, example2
All corner0, corner1, corner2, corner3, example0, example1, example2, maxrand0, maxrand1, maxrand2, rand0, rand1, rand2
Case Name Status Exec Time Memory
corner0 AC 152 ms 16780 KB
corner1 TLE 2109 ms 16780 KB
corner2 AC 7 ms 1788 KB
corner3 TLE 2108 ms 16780 KB
example0 AC 7 ms 1788 KB
example1 AC 7 ms 1788 KB
example2 AC 7 ms 1788 KB
maxrand0 AC 332 ms 16780 KB
maxrand1 AC 316 ms 16780 KB
maxrand2 AC 313 ms 16780 KB
rand0 AC 7 ms 1788 KB
rand1 AC 7 ms 1788 KB
rand2 AC 7 ms 1788 KB