QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#635145 | #9454. String of CCPC | ucup-team3659# | AC ✓ | 14ms | 4176kb | C++20 | 1.1kb | 2024-10-12 19:09:03 | 2024-10-12 19:09:04 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
string a;
void test()
{
cin>>n>>a;
a=" "+a+"ywzakioi";
int cnt=0,ans=0;
for(int i=1;i<=n-3;i++)
cnt+=(a[i]=='C'&&a[i+1]=='C'&&a[i+2]=='P'&&a[i+3]=='C');
ans=cnt;
for(int i=0;i<=n;i++)
{
int newans=cnt;
if(i-2>=0&&i-2+3<=n)
newans-=(a[i-2]=='C'&&a[i-1]=='C'&&a[i]=='P'&&a[i+1]=='C');
if(i-1>=0&&i-1+3<=n)
newans-=(a[i-1]=='C'&&a[i]=='C'&&a[i+1]=='P'&&a[i+2]=='C');
if(i>=0&&i+3<=n)
newans-=(a[i]=='C'&&a[i+1]=='C'&&a[i+2]=='P'&&a[i+3]=='C');
int delans=newans;
if(i-2>=0&&i<=n)
newans+=(a[i-2]=='C'&&a[i-1]=='C'&&a[i]=='P');
if(i>=0&&i+2<=n)
newans+=(a[i]=='C'&&a[i+1]=='P'&&a[i+2]=='C');
if(i+3<=n)
newans+=(a[i+1]=='C'&&a[i+2]=='P'&&a[i+3]=='C');
ans=max(ans,newans);
newans=delans;
if(i-1>=0&&i+1<=n)
newans+=(a[i-1]=='C'&&a[i]=='C'&&a[i+1]=='C');
ans=max(ans,newans);
}
cout<<ans<<"\n";
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
for(int i=1;i<=t;i++)
test();
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3840kb
input:
3 3 CCC 5 CCCCP 4 CPCP
output:
1 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 14ms
memory: 4176kb
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