QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#633751 | #9454. String of CCPC | ucup-team3564# | AC ✓ | 40ms | 30656kb | C++14 | 2.1kb | 2024-10-12 16:09:23 | 2024-10-12 16:09:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long T,a,b,c,d[1000001],v[1000001],o,h[1000001],fa[1000001],q,w,e,an,cn,fac[1000001],inv[1000001],st[1000001],u[1000001];
long long dp[200001][4][8];
char s[1000001];
struct p{long long q,w;}l[1000001];
long long pow_(long long qq,long long ww){long long ee=1;while(ww){if(ww&1) ee*=qq,ee%=mod;qq*=qq,qq%=mod,ww>>=1;}return ee%mod;}
inline int read(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}return x*f;}
void add(long long qq,long long ww){l[++o].q=ww,l[o].w=h[qq],h[qq]=o;}
long long gcd(long long qq,long long ww){return !ww?qq:gcd(ww,qq%ww);}
long long find(long long qq){return qq==fa[qq]?qq:fa[qq]=find(fa[qq]);}
void merge(long long qq,long long ww){long long f1=find(qq),f2=find(ww);if(f1==f2) return;fa[f1]=f2;}
long long C(long long qq,long long ww){return fac[qq]*inv[ww]%mod*inv[qq-ww]%mod;}
int main()
{
// freopen("1.in","r",stdin);
srand((unsigned)(time(0)^(*new int)));
fac[0]=1;for(int i=1;i<=1000000;i++) fac[i]=fac[i-1]*i%mod;
inv[1000000]=pow_(fac[1000000],mod-2);for(int i=999999;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
T=1;
scanf("%lld",&T);
for(int ii=1;ii<=T;ii++)
{
scanf("%lld",&a);
scanf("%s",s+1);
long long smm=0;
for(int i=4;i<=a;i++)
{
if(s[i]=='C'&&s[i-1]=='P'&&s[i-2]=='C'&&s[i-3]=='C') ++smm,v[i-3]=1;
else v[i-3]=0;
}an=0;
for(int i=1;i<=a+1;i++)
{
long long L=max(i-4,1);
long long R=min(a,(long long)i+4);
long long hh=0;
for(int j=L;j<=R-3;j++)
{
hh-=v[j];
}
long long g1=0,g2=0;
cn=0;
for(int j=L;j<=i-1;j++) st[++cn]=(s[j]=='C');
st[++cn]=1;
for(int j=i;j<=R;j++) st[++cn]=(s[j]=='C');
for(int j=1;j<=cn-3;j++)
{
if(st[j]&&st[j+1]&&!st[j+2]&&st[j+3]) ++g1;
}
cn=0;
for(int j=L;j<=i-1;j++) st[++cn]=(s[j]=='C');
st[++cn]=0;
for(int j=i;j<=R;j++) st[++cn]=(s[j]=='C');
for(int j=1;j<=cn-3;j++)
{
if(st[j]&&st[j+1]&&!st[j+2]&&st[j+3]) ++g2;
}
an=max(an,hh+max(g1,g2));
}
printf("%lld\n",an+smm);
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 28552kb
input:
3 3 CCC 5 CCCCP 4 CPCP
output:
1 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 40ms
memory: 30656kb
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