QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#686513#9454. String of CCPCir101#WA 11ms10088kbC++201.1kb2024-10-29 13:57:022024-10-29 13:57:02

Judging History

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

  • [2024-10-29 13:57:02]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:10088kb
  • [2024-10-29 13:57:02]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define endl '\n'
#define int long long
#define  lc p<<1
#define  rc p<<1|1
using namespace  std;
const int N = 2e5 + 10;
int cnt = 0;
string s;
int a[N],b[N];
int f1[N],f2[N];
void solve() {
	
	int n;
	cin>>n;
	cin >> s;
	for(int i=0;i<n-3;i++){
		if(s[i]=='C'&&s[i+1]=='C'&&s[i+2]=='P'&&s[i+3]=='C'){
			a[i+3]++;
			b[i]++;
		}
	}
	for(int i=1;i<=n;i++){
		f1[i]=f1[i-1]+a[i-1];
	}
	f2[n+1]=0;
	for(int i=n;i>=1;i--){
		f2[i]=f2[i+1]+b[i-1];
	}
	int ans=f1[n];
	for(int i=0;i<=n;i++){
		int s1=0,s2=0;
		if(i+3<=n&&s[i]=='C'&&s[i+1]=='P'&&s[i+2]=='C'){
			s1++;
		}
		if(i>=1&&i+2<=n&&s[i-1]=='C'&&s[i]=='P'&&s[i+1]=='C'){
			s1++;
		}
		if(i>=2&&i+1<=n&&s[i-2]=='C'&&s[i-1]=='C'&&s[i]=='C'){
			s2++;
		}
		if(i>=3&&i<=n&&s[i-3]=='C'&&s[i-2]=='C'&&s[i-1]=='P'){
			s1++;
		}
		ans=max(ans,f1[i]+f2[i+1]+max(s1,s2));
//		cout<<f1[i]<<' '<<f2[i+1]<<' '<<max(s1,s2)<<endl;
	}
	cout<<ans<<endl;
}
signed main() {
	 ios::sync_with_stdio(false),cin.tie(0);
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3648kb

input:

3
3
CCC
5
CCCCP
4
CPCP

output:

1
1
1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 11ms
memory: 10088kb

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
2
1
2
3
3
3
4
5
5
5
6
6
2
7
5
9
11
7
11
11
11
13
7
10
13
16
16
17
18
11
20
20
19
9
6
4
23
20
10
9
21
10
23
13
13
10
6
23
14
5
11
11
23
14
26
26
24
7
26
26
27
31
32
12
28
31
29
13
35
30
32
37
40
39
41
41
43
10
35
42
10
42
43
27
22
22
47
24
48
35
23
50
49
35
42
18
46
18
52
31
32
56
58
57
28
59
45
20...

result:

wrong answer 2nd lines differ - expected: '1', found: '2'