QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#635212 | #9454. String of CCPC | ucup-team3586# | AC ✓ | 14ms | 4088kb | C++23 | 1.4kb | 2024-10-12 19:17:35 | 2024-10-12 19:17:35 |
Judging History
answer
#include<bits/stdc++.h>
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
#define int long long
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
const int p=998244353;
int qp(int x,int y)
{
int res=1;
for(int t=x; y; y>>=1,t=1ll*t*t%p)
if(y&1) res=1ll*res*t%p;
return res;
}
char s[1<<20];
signed main()
{
for(int T=read();T--;)
{
int n=read();
scanf("%s",s+1);
int A=0;
for(int i=1; i+3<=n; ++i)
if(s[i]=='C'&&s[i+1]=='C'&&s[i+2]=='P'&&s[i+3]=='C') ++A;
int ans=A;
auto chk=[&](int i)
{
if(i<1||i+3>n) return 0;
if(s[i]=='C'&&s[i+1]=='C'&&s[i+2]=='P'&&s[i+3]=='C') return 1;
return 0;
};
for(int i=0; i<=n; ++i) //after there
{
int B=A;
B-=chk(i-2);
B-=chk(i-1);
B-=chk(i);
int B1=0,B2=0;
if(i+3<=n&&s[i+1]=='C'&&s[i+2]=='P'&&s[i+3]=='C') ++B1;
if(i>=1&&i+2<=n&&s[i]=='C'&&s[i+1]=='P'&&s[i+2]=='C') ++B1;
if(i>=2&&i+1<=n&&s[i-1]=='C'&&s[i]=='C'&&s[i+1]=='C') ++B2;
if(i>=3&&s[i-2]=='C'&&s[i-1]=='C'&&s[i]=='P') ++B1;
ans=max(ans,B+B1);
ans=max(ans,B+B2);
}
printf("%lld\n",ans);
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3904kb
input:
3 3 CCC 5 CCCCP 4 CPCP
output:
1 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 14ms
memory: 4088kb
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