QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#363697#7695. Double Uplucasrpatten#TL 1069ms70680kbPython3843b2024-03-24 02:02:212024-03-24 02:02:21

Judging History

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

  • [2024-03-24 02:02:21]
  • 评测
  • 测评结果:TL
  • 用时:1069ms
  • 内存:70680kb
  • [2024-03-24 02:02:21]
  • 提交

answer

import sys
sys.setrecursionlimit(10000)
input()
l=[int(i) for i in input().split()]
d={}
def dp(i,j):
    if j-i==1:
        return l[i]
    if (i,j) in d:
        return d[(i,j)]
    ans=0
    a=dp(i,j-1)
    b=dp(i+1,j)
    if a!=b:
        d[(i,j)]=max(a,b)
        return d[(i,j)]
    lo=i+1
    hi=j-1
    while hi-lo>1:
        m=(hi+lo)//2
        e=dp(i,m)
        f=dp(m,j)
        if e<a and f<a:
            d[(i,j)]=a
            return a
        if e==a and f==a:
            d[(i,j)]=2*a
            return 2*a
        if e<a:
            lo=m
        else:
            hi=m
    for k in range(i+1,j):
        a=dp(i,k)
        b=dp(k,j)
        if a==b:
            ans=max(ans,2*a)
        else:
            ans=max(ans,max(a,b))
    d[(i,j)]=ans
    return d[(i,j)]
print(dp(0,len(l)))

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 9ms
memory: 9552kb

input:

5
4 2 2 1 8

output:

16

result:

ok single line: '16'

Test #2:

score: 0
Accepted
time: 1035ms
memory: 70348kb

input:

1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

512

result:

ok single line: '512'

Test #3:

score: 0
Accepted
time: 1069ms
memory: 70680kb

input:

1000
1267650600228229401496703205376 1267650600228229401496703205376 1267650600228229401496703205376 1267650600228229401496703205376 1267650600228229401496703205376 1267650600228229401496703205376 1267650600228229401496703205376 1267650600228229401496703205376 1267650600228229401496703205376 1267650...

output:

649037107316853453566312041152512

result:

ok single line: '649037107316853453566312041152512'

Test #4:

score: 0
Accepted
time: 6ms
memory: 9424kb

input:

1
1

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 3ms
memory: 9460kb

input:

1
2

output:

2

result:

ok single line: '2'

Test #6:

score: 0
Accepted
time: 9ms
memory: 9436kb

input:

1
4294967296

output:

4294967296

result:

ok single line: '4294967296'

Test #7:

score: 0
Accepted
time: 3ms
memory: 9384kb

input:

1
18446744073709551616

output:

18446744073709551616

result:

ok single line: '18446744073709551616'

Test #8:

score: 0
Accepted
time: 3ms
memory: 9548kb

input:

1
1267650600228229401496703205376

output:

1267650600228229401496703205376

result:

ok single line: '1267650600228229401496703205376'

Test #9:

score: 0
Accepted
time: 386ms
memory: 17116kb

input:

384
18014398509481984 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 72057594037927936 10737418...

output:

618970019642690137449562112

result:

ok single line: '618970019642690137449562112'

Test #10:

score: -100
Time Limit Exceeded

input:

430
36893488147419103232 128 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248 2251799813685248...

output:


result: