QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#692252 | #9454. String of CCPC | ucup-team5217# | AC ✓ | 214ms | 4012kb | C++23 | 1.3kb | 2024-10-31 14:12:10 | 2024-10-31 14:12:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
void solve(void) {
int n;
cin>>n;
string s;
cin>>s;
int sz=s.size();int ans=0;
for(int i=3;i<sz;i++){
if(s.substr(i-3,4)=="CCPC") ans++;
}
int maxn=ans;
auto get=[&](int x)->int {
if(x<0||x+3>sz-1) return 0;
return s.substr(x,4)=="CCPC";
};
for(int i=0;i<=n;i++){
int res=ans;
for(int j=i-1;j>=i-3;j--){
res-=get(j);
}
for(int j=i;j>=i-3;j--){
if(j<0||j+2>sz-1) continue;
string w=s.substr(j,3);
int lo=(i-j);
w=w.substr(0,lo)+"P"+w.substr(lo);
if(w=="CCPC") res++;
}
maxn=max(maxn,res);
}
for(int i=0;i<=n;i++){
int res=ans;
for(int j=i-1;j>=i-3;j--){
res-=get(j);
}
for(int j=i;j>=i-3;j--){
if(j<0||j+2>sz-1) continue;
string w=s.substr(j,3);
int lo=(i-j);
w=w.substr(0,lo)+"C"+w.substr(lo);
if(w=="CCPC") res++;
}
maxn=max(maxn,res);
}
cout<<maxn<<'\n';
}
int main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int _ = 1;
cin >> _;
while (_--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
input:
3 3 CCC 5 CCCCP 4 CPCP
output:
1 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 214ms
memory: 4012kb
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