QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#420909#6430. Monster HuntershaletomeRE 0ms0kbPython32.6kb2024-05-25 03:14:082024-05-25 03:14:09

Judging History

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

  • [2024-05-25 03:14:09]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-05-25 03:14:08]
  • 提交

answer

# Left side, 3rd row, inner desk BYU


from itertools import accumulate
for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    a1=[v==1 for v in a]
    a2=[v==2 for v in a]
    a3=[v==3 for v in a]
    c1=list(accumulate(a1+a1,initial=0))
    c2=list(accumulate(a2+a2,initial=0))
    c3=list(accumulate(a3+a3,initial=0))

    ap=list(accumulate(a,initial=0))
    # print(ap)
    m=int(input())
    for i in range(m*2):
        c1.append(c1[-1]+1 if a[i%n]==1 else c1[-1])
        c2.append(c2[-1]+1 if a[i%n]==2 else c2[-1])
        c2.append(c3[-1]+1 if a[i%n]==3 else c3[-1])
    h=list(map(int,input().split()))
    th=sum(h)
    ta=ap[-1]
    ans,th=divmod(th,ta)
    for i in range(n+1):
        if ap[i] >= th:break
    n1=c1[n]*ans+c1[i]
    n2=c2[n]*ans+c2[i]
    n3=c3[n]*ans+c3[i]
    i%=n
    lo=0
    hi=2*m+n-1
    nx=[0]*8
    n6=0
    for hv in h:
        n6+=hv//6
        if hv%6==1:
            if hv==1:
                nx[1]+=1
            else:
                nx[7]+=1
                n6-=1
        else:
            nx[hv%6]+=1
    # print(n6,nx)
    def test(n1,n2,n3,nx):
        # print(n1,n2,n3)
        for j in [2,5]:
            ts=min(n2,nx[j])
            nx[j-2]+=ts
            nx[j]-=ts
            n2-=ts
        for j in [4,7]:
            ts=min(n2//2,nx[j])
            nx[j-4]+=ts
            nx[j]-=ts
            n2-=ts*2
        for j in [3,7,5,4]:
            ts=min(n3,nx[j])
            nx[j-3]+=ts
            nx[j]-=ts
            n3-=ts
        for j in [7,5,4,3,2]:
            ts=min(n2,nx[j])
            nx[j-2]+=ts
            nx[j]-=ts
            n2-=ts
        for j in [7,6,5,4,3]:
            if n1<nx[j]:return False
            nx[j-1]+=nx[j]
            n1-=nx[j]
            nx[j]=0
        # print(n1,n2,n3)
        # print(nx)
        v1=min(n1,nx[1])
        n1-=v1
        nx[1]-=v1
        nx[0]+=v1

        v2=min(n1//2,nx[2])
        n1-=v2*2
        nx[2]-=v2
        nx[0]+=v2

        v1=min(n2,nx[1])
        n2-=v1
        nx[1]-=v1
        nx[0]+=v1

        v1=min(n3,nx[2])
        n3-=v1
        nx[2]-=v1
        nx[0]+=v1

        v1=min(n3,nx[1])
        n3-=v1
        nx[1]-=v1
        nx[0]+=v1

        # print(n1,n2,n3)
        # print(nx)

        if any(nx[1:]):return False
        return (n1+2*n2+3*n3)>=n6*6
        return False
    while lo!=hi:
        mid=(lo+hi)//2
        if test(n1+c1[i+mid]-c1[i],
                n2+c2[i+mid]-c2[i],
                n3+c3[i+mid]-c3[i], nx.copy()):
            hi=mid
            # print("hi",hi,mid)
        else:
            lo=mid+1
            # print("lo",lo,mid)
    print(ans*n+i+hi)
    # print(ans)

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

3
5
1 2 3 4
1 2 3 4 5
9
1 2 3 4 3 4 6 6
8 4 9 4 4 5 2 4 1
12
1 2 2 4 5 3 4 3 8 10 11
9 1 3 5 10 10 7 3 7 9 4 9

output:


result: