QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#632761#9454. String of CCPCucup-team3161#AC ✓139ms3800kbC++171.1kb2024-10-12 13:54:522024-10-12 13:54:55

Judging History

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

  • [2024-10-12 13:54:55]
  • 评测
  • 测评结果:AC
  • 用时:139ms
  • 内存:3800kb
  • [2024-10-12 13:54:52]
  • 提交

answer

#include <bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
//#define int long long
using namespace std;

#define maxn 200005 
#define inf 0x3f3f3f3f

int n;
string s;

void work()
{
    cin>>n>>s;
    int res=0;
    For(i,0,n-4) if(s.substr(i,4)=="CCPC") ++res;
    int sum=res;
    For(i,0,n) {
        for(auto ch:{'C','P'}){
            int now=sum;
            Rep(j,i-1,i-3)
                if(j>=0 && j<=n-4) {
                    if(s.substr(j,4)=="CCPC") --now;
                }
            For(k,i-3,i) if(k>=0){
                int p=k;
                string ss;
                For(t,0,3){
                    if(t==(i-k)) ss+=ch;
                    else if(p>=n)break;
                    else ss+=s[p],++p;
                }
                if(ss=="CCPC") ++now;
            }
         //   if(now==3) cout<<"??? "<<i<<" "<<ch<<"\n";
            res=max(res,now);
        }
    }
    cout<<res<<"\n";
}
signed main()
{
  //  freopen("my.out","w",stdout);
    int T;cin>>T;
    while(T--)work();
    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3800kb

input:

3
3
CCC
5
CCCCP
4
CPCP

output:

1
1
1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 139ms
memory: 3732kb

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