QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#632521 | #9454. String of CCPC | ucup-team4717# | AC ✓ | 25ms | 19820kb | C++17 | 2.0kb | 2024-10-12 13:30:57 | 2024-10-12 13:31:04 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace IO{
char buff[1<<21],*p1=buff,*p2=buff;
char getch(){
return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
}
template<typename T>
void read(T &x){
char ch=getch();int fl=1;x=0;
while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
x*=fl;
}
template<typename T,typename ...Args>
void read(T &x,Args& ...args){
read(x);read(args...);
}
char obuf[1<<21],*p3=obuf;
void putch(char ch){
if(p3-obuf<(1<<21))*p3++=ch;
else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
}
char ch[100];
template<typename T>
void write(T x){
if(!x)return putch('0');
if(x<0)putch('-'),x*=-1;
int top=0;
while(x)ch[++top]=x%10+48,x/=10;
while(top)putch(ch[top]),top--;
}
template<typename T,typename ...Args>
void write(T x,Args ...args){
write(x),putch(' '),write(args...);
}
void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=2e5+5;
void Work(int *a,int *b,int ops){
if(ops==0){
b[1]=max(b[1],a[0]);
b[2]=max(b[2],a[1]);
b[2]=max(b[2],a[2]);
b[1]=max(b[1],a[3]+1);
}else{
b[0]=max(b[0],a[0]);
b[0]=max(b[0],a[1]);
b[3]=max(b[3],a[2]);
b[0]=max(b[0],a[3]);
}
}
int n;
int a[N];
int f[N][4][4];
void sol(){
read(n);
for(int i=1;i<=n;i++){
char ch=getch();
while(ch!='C'&&ch!='P')ch=getch();
if(ch=='C')a[i]=0;
else a[i]=1;
}
memset(f[0],-0x3f,sizeof f[0]);
f[0][0][0]=0;
for(int i=1;i<=n;i++){
memset(f[i],-0x3f,sizeof f[i]);
for(int j=0;j<4;j++)Work(f[i-1][j],f[i][j],a[i]);
for(int j=1;j<4;j++)Work(f[i][j-1],f[i][j],0),Work(f[i][j-1],f[i][j],1);
}
int ans=0;
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
ans=max(ans,f[n][i][j]-(i*(i-1)/2));
write(ans),putch('\n');
}
signed main(){
int T;
read(T);
while(T--)sol();
flush();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7652kb
input:
3 3 CCC 5 CCCCP 4 CPCP
output:
1 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 25ms
memory: 19820kb
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