QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#636774#9454. String of CCPCucup-team4810#AC ✓287ms11108kbPython3717b2024-10-13 02:45:102024-10-13 02:45:11

Judging History

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

  • [2024-10-13 02:45:11]
  • 评测
  • 测评结果:AC
  • 用时:287ms
  • 内存:11108kb
  • [2024-10-13 02:45:10]
  • 提交

answer

from functools import *
@lru_cache(None)
def f(l,r):
    ans=0
    ss=l+r
    ic = sum(ss[j:j+4]=='CCPC' for j in range(3))
    for nc in 'CP':
        nss = l+nc+r
        nic = sum(nss[j:j+4]=='CCPC' for j in range(4))
        # print(ss,nss,nic,ic)
        if nic>ic:
            ans=max(ans,nic-ic)
    return ans

def score(s):
    rp=-1
    ans = 0
    for i in range(len(s)):
        c=s[i]
        if s[i:i+2]=='PC' and rp <=i-3:
            ans += 1
        if s[i]=='P':
            rp=i
    return ans

def tc():
    n=int(input())
    s=input()
    ans = 0
    print(any(f(s[max(0,i-3):i],s[i:i+3]) for i in range(n+1)) + score(s))

for _ in range(int(input())):
    tc()

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 17ms
memory: 10576kb

input:

3
3
CCC
5
CCCCP
4
CPCP

output:

1
1
1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 287ms
memory: 11108kb

input:

20003
5
PCCPC
10
CPPPPCPCPC
4
CPPC
11
CCPPCPPPCCP
17
PPPPCPCCCCCPCCCCC
10
PPCCPCPPCP
9
CPCCCCPPC
11
PCPPPPCCPPP
15
CPCPPPPCCPCPCCC
11
PCCPPCCPCPP
9
PCPCCPPCP
10
CCPCPPPCPP
14
CCCCPPPCPCPCPP
2
CC
12
CCPCPPPPPCPP
6
CPPPPP
12
PCCPCCCCCPCC
16
CPCCPCCPPCCCCPPC
7
CPPPCPC
16
PPPPPCCPCPCPCPPC
13
PPPCPCCCCPP...

output:

1
1
0
1
2
1
1
1
2
2
1
1
1
0
1
0
3
2
1
2
1
2
2
0
1
2
3
1
1
3
1
2
2
1
0
0
0
3
1
0
0
1
1
2
0
1
1
0
1
2
0
1
0
1
0
3
1
1
0
2
1
3
2
2
0
2
2
0
0
2
1
1
3
3
1
3
1
2
0
1
1
0
1
2
2
1
1
2
1
3
1
1
3
1
2
2
0
1
0
3
0
1
1
2
2
0
2
1
1
2
2
0
3
1
1
1
1
2
1
2
0
1
1
0
3
0
3
1
1
0
0
1
0
3
0
1
1
1
1
2
2
1
1
0
0
1
2
0
1
2
...

result:

ok 20003 lines

Extra Test:

score: 0
Extra Test Passed