QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#567189#9313. Make MaxWeiAnTL 15ms10700kbPython33.6kb2024-09-16 09:50:322024-09-16 09:50:32

Judging History

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

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

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:
        # print(arrnow)
        # print(arrcnt)
        pos = arrnow.index(min(arrnow))
        # print(pos)
        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-1] += arrcnt[pos]
                    ans += arrcnt[pos]
                    arrnow.pop(pos)
                    arrcnt.pop(pos)
                else:
                    arrcnt[pos+1] += arrcnt[pos]
                    ans += arrcnt[pos]
                    arrnow.pop(pos)
                    arrcnt.pop(pos)
            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]
            # print(mid,right)
            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("!!")
        # print(ans)
        # print(arrnow)
        # print(arrcnt)
    print(ans)

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 15ms
memory: 10700kb

input:

4
2
1 2
2
2 2
7
1 1 1 2 2 2 2
3
1 2 3

output:

1
0
3
3

result:

ok 4 number(s): "1 0 3 3"

Test #2:

score: -100
Time Limit Exceeded

input:

2
198018
875421126 585870339 471894633 383529988 625397685 944061047 704695631 105113224 459022561 760848605 980735314 847376362 980571959 329939331 644635272 326439858 752879510 837384394 175179068 182094523 397239381 1199016 185143405 279638454 252374970 822030887 860312140 137248166 993229443 164...

output:


result: