QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#640886 | #9454. String of CCPC | lonlyness | AC ✓ | 15ms | 6036kb | C++23 | 1.6kb | 2024-10-14 16:41:18 | 2024-10-14 16:41:19 |
Judging History
answer
// _ _ _
// | | ___ _ __ ___ | | (_) _ __ ___ ___ ___
// | | / _ \ | '_ \ / _ \ | | | | | '_ \ / _ \ / __| / __|
// | | | (_) | | | | | | __/ | | | | | | | | | __/ \__ \ \__ \
// |_| \___/ |_| |_| \___| |_| |_| |_| |_| \___| |___/ |___/
//
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<unordered_map>
using namespace std;
#define int long long
#define endl "\n"
const int N = 1e6+10,mod=1e9+13;
typedef pair<int,int> PII;
int n,m;
void solve()
{
string s;
cin>>n>>s;
string tem;
vector<int>d(n+1,0);
for(int i = n-1;i >= 0; i --){
d[i]=d[i+1];
if(n-i>=4&&s[i]=='C'&&s[i+1]=='C'&&s[i+2]=='P'&&s[i+3]=='C')d[i]++;
}
int ans = 0;
int cnt = 0;
for(int i = 0;i < n;i ++){
if(i>2){
if(s[i]=='C'&&s[i-1]=='P'&&s[i-2]=='C'&&s[i-3]=='C')cnt++;
}
int cntc=0,cntp=0;
if(i+3<n&&s[i+1]=='C'&&s[i+2]=='P'&&s[i+3]=='C')cntc++;
if(i>=0&&i+2<n&&s[i]=='C'&&s[i+1]=='P'&&s[i+2]=='C')cntc++;
if(i-2>=0&&s[i-2]=='C'&&s[i-1]=='C'&&s[i]=='P')cntc++;
ans = max(ans,cntc+cnt+d[i+1]);
if(i-1>=0&&i+1<n&&s[i-1]=='C'&&s[i]=='C'&&s[i+1]=='C')cntp++;
ans = max(ans,cntp+cnt+d[i+1]);
}
cout<<ans<<endl;
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
while(t--){
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3632kb
input:
3 3 CCC 5 CCCCP 4 CPCP
output:
1 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 15ms
memory: 6036kb
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