QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#567182#9313. Make MaxWeiAnWA 15ms10696kbPython33.4kb2024-09-16 09:41:422024-09-16 09:41:42

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 15:56:24]
  • hack成功,自动添加数据
  • (/hack/836)
  • [2024-09-16 09:41:42]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:10696kb
  • [2024-09-16 09:41:42]
  • 提交

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'