QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#686551 | #9454. String of CCPC | ir101# | AC ✓ | 14ms | 10016kb | C++20 | 1.2kb | 2024-10-29 14:14:13 | 2024-10-29 14:14:14 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define endl '\n'
#define int long long
#define lc p<<1
#define rc p<<1|1
using namespace std;
const int N = 2e5 + 10;
int cnt = 0;
string s;
int a[N],b[N];
int f1[N],f2[N];
void solve() {
int n;
cin>>n;
cin >> s;
for(int i=0;i<=n+1;i++){
a[i]=b[i]=0;
f1[i]=f2[i]=0;
}
for(int i=0;i<n-3;i++){
if(s[i]=='C'&&s[i+1]=='C'&&s[i+2]=='P'&&s[i+3]=='C'){
a[i+3]++;
b[i]++;
}
}
for(int i=1;i<=n;i++){
f1[i]=f1[i-1]+a[i-1];
}
f2[n+1]=0;
for(int i=n;i>=1;i--){
f2[i]=f2[i+1]+b[i-1];
}
int ans=f1[n];
for(int i=0;i<=n;i++){
int s1=0,s2=0;
if(i+3<=n&&s[i]=='C'&&s[i+1]=='P'&&s[i+2]=='C'){
s1++;
}
if(i>=1&&i+2<=n&&s[i-1]=='C'&&s[i]=='P'&&s[i+1]=='C'){
s1++;
}
if(i>=2&&i+1<=n&&s[i-2]=='C'&&s[i-1]=='C'&&s[i]=='C'){
s2++;
}
if(i>=3&&i<=n&&s[i-3]=='C'&&s[i-2]=='C'&&s[i-1]=='P'){
s1++;
}
ans=max(ans,f1[i]+f2[i+1]+max(s1,s2));
// cout<<f1[i]<<' '<<f2[i+1]<<' '<<max(s1,s2)<<endl;
}
cout<<ans<<endl;
}
signed main() {
ios::sync_with_stdio(false),cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 7676kb
input:
3 3 CCC 5 CCCCP 4 CPCP
output:
1 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 14ms
memory: 10016kb
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