QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#567182 | #9313. Make Max | WeiAn | WA | 15ms | 10696kb | Python3 | 3.4kb | 2024-09-16 09:41:42 | 2024-09-16 09:41:42 |
Judging History
answer
T = int(input())
for _ in range(T):
n = int(input())
arr = map(int, input().split())
arrnow = []
arrcnt = []
now = 0
cnt = 0
for i in arr:
if i == now:
cnt += 1
else:
if cnt != 0:
arrnow.append(now)
arrcnt.append(cnt)
now = i
cnt = 1
if cnt != 0:
arrnow.append(now)
arrcnt.append(cnt)
# print(arrnow)
# print(arrcnt)
ans = 0
while len(arrnow) > 1:
pos = arrnow.index(max(arrnow))
if pos >= 1 and pos < len(arrnow)-1:
left = arrnow[pos-1]
right = arrnow[pos+1]
mid = arrnow[pos]
if mid == left:
arrcnt[pos-1] += arrcnt[pos]
arrnow.pop(pos)
arrcnt.pop(pos)
elif mid == right:
arrcnt[pos+1] += arrcnt[pos]
arrnow.pop(pos)
arrcnt.pop(pos)
elif left < mid < right:
arrcnt[pos] += arrcnt[pos-1]
ans += arrcnt[pos-1]
arrnow.pop(pos-1)
arrcnt.pop(pos-1)
elif left > mid > right:
arrcnt[pos] += arrcnt[pos+1]
ans += arrcnt[pos+1]
arrnow.pop(pos+1)
arrcnt.pop(pos+1)
elif left > mid and mid < right:
if left < right:
arrcnt[pos] += arrcnt[pos-1]
ans += arrcnt[pos-1]
arrnow.pop(pos-1)
arrcnt.pop(pos-1)
else:
arrcnt[pos] += arrcnt[pos+1]
ans += arrcnt[pos+1]
arrnow.pop(pos+1)
arrcnt.pop(pos+1)
elif mid > left and mid > right:
if left < right:
arrcnt[pos] += arrcnt[pos-1]
ans += arrcnt[pos-1]
arrnow.pop(pos-1)
arrcnt.pop(pos-1)
else:
arrcnt[pos] += arrcnt[pos+1]
ans += arrcnt[pos+1]
arrnow.pop(pos+1)
arrcnt.pop(pos+1)
elif pos == 0:
right = arrnow[pos+1]
mid = arrnow[pos]
if mid == right:
arrcnt[pos+1] += arrcnt[pos]
arrnow.pop(pos)
arrcnt.pop(pos)
elif mid < right:
arrcnt[pos+1] += arrcnt[pos]
ans += arrcnt[pos]
arrnow.pop(pos)
arrcnt.pop(pos)
elif mid > right:
arrcnt[pos] += arrcnt[pos+1]
ans += arrcnt[pos+1]
arrnow.pop(pos+1)
arrcnt.pop(pos+1)
else:
left = arrnow[pos-1]
mid = arrnow[pos]
if mid == left:
arrcnt[pos-1] += arrcnt[pos]
arrnow.pop(pos)
arrcnt.pop(pos)
elif mid < left:
arrcnt[pos-1] += arrcnt[pos]
ans += arrcnt[pos]
arrnow.pop(pos)
arrcnt.pop(pos)
elif mid > left:
arrcnt[pos] += arrcnt[pos-1]
ans += arrcnt[pos-1]
arrnow.pop(pos-1)
arrcnt.pop(pos-1)
print(ans)
詳細信息
Test #1:
score: 0
Wrong Answer
time: 15ms
memory: 10696kb
input:
4 2 1 2 2 2 2 7 1 1 1 2 2 2 2 3 1 2 3
output:
1 0 3 2
result:
wrong answer 4th numbers differ - expected: '3', found: '2'