QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#633960#9454. String of CCPCucup-team5075#AC ✓64ms23464kbC++141.8kb2024-10-12 16:29:132024-10-12 16:29:16

Judging History

你现在查看的是最新测评结果

  • [2024-10-12 16:29:16]
  • 评测
  • 测评结果:AC
  • 用时:64ms
  • 内存:23464kb
  • [2024-10-12 16:29:13]
  • 提交

answer

//Linkwish's code
#include<bits/stdc++.h>
#define endl '\n'
#define si inline
#define fi first
#define se second
using namespace std;
typedef long long ll;typedef __int128 li;typedef long double ld;
typedef pair<int,int> pii;typedef pair<ll,ll> pll;
typedef const int ci;typedef const ll cl;ci iinf=1e9;cl linf=LLONG_MAX;
template<typename T>si bool gmax(T &x,const T y){if(x<y)return x=y,1;return 0;}
template<typename T>si bool gmin(T &x,const T y){if(y<x)return x=y,1;return 0;}

namespace LinkWish{

	ci N=200005;

	int n;
	string s;

	int f[N][5][5];
	char ned[4]={'C','C','P','C'};

	si void solve(){
		cin>>n>>s,s=' '+s;
		for(int i=0;i<=n+1;i++)
			for(int j=0;j<5;j++)
				for(int k=0;k<5;k++)
					f[i][j][k]=-iinf;
		
		f[0][0][0]=0;
		for(int i=0;i<=n;i++){
			for(int j=0;j<5;j++){
				for(int k=0;k<4;k++){
					if(i<n&&s[i+1]==ned[k])gmax(f[i+1][j][k+1],f[i][j][k]);
					else{
						if(k==2&&s[i+1]=='C')gmax(f[i+1][j][2],f[i][j][k]);
						else if(s[i+1]=='C')gmax(f[i+1][j][1],f[i][j][k]);
						else gmax(f[i+1][j][0],f[i][j][k]);
					}
					if(j<4){
						gmax(f[i][j+1][k+1],f[i][j][k]-j);
						gmax(f[i][j+1][0],f[i][j][k]-j);
					}
				}
				if(j<4){
					gmax(f[i][j+1][2],f[i][j][4]-j+1);
					gmax(f[i][j+1][0],f[i][j][4]-j+1);
				}
				if(i<n&&s[i+1]=='C')gmax(f[i+1][j][2],f[i][j][4]+1);
				else gmax(f[i+1][j][0],f[i][j][4]+1);
			}
		}

		int ans=-iinf;
		for(int i=0;i<5;i++)
			for(int j=0;j<5;j++)
				gmax(ans,f[n+1][i][j]);

		cout<<ans<<endl;
	}

	void mian(){
		int TT;cin>>TT;
		while(TT--)solve();
	}
}

signed main(){
	#ifndef ONLINE_JUDGE
	assert(freopen("in.in","r",stdin));
	// assert(freopen("out.out","w",stdout));
	assert(freopen("out.err","w",stderr));
	#endif
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);   
	LinkWish::mian();
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3512kb

input:

3
3
CCC
5
CCCCP
4
CPCP

output:

1
1
1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 64ms
memory: 23464kb

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