QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#716218 | #9454. String of CCPC | oqmsac | AC ✓ | 12ms | 5204kb | C++23 | 1.0kb | 2024-11-06 14:41:24 | 2024-11-06 14:41:25 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<ll,ll>
using namespace std;
//#pragma GCC optimize(3)
const ll inf =(1ll<<50);
#define N 10000005
#define M 998244353
#define M1 1000000007
#define M2 1000000009
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
cin>>T;
while(T--) {
int n;
string s;
cin >>n>> s;
vector<ll> pos;
pos.push_back(-1);
ll flag=0,cnt=0;
for(int i=0;i<n;i++)
{
if(s[i]=='P') pos.push_back(i);
}
pos.push_back(n);
for(int i=1;i<pos.size()-1;i++)
{
if(pos[i]-pos[i-1]>2&&pos[i+1]-pos[i]>1) cnt++;
else if(pos[i]-pos[i-1]>2) flag=1;
else if(pos[i]-pos[i-1]>1&&pos[i+1]-pos[i]>1) flag=1;
if(pos[i]-pos[i-1]>4) flag=1;
}
if(pos[pos.size()-1]-pos[pos.size()-2]>3) flag=1;
cout<<cnt+flag<<endl;
}
return 0;
}
//1 5
//32 32 15 15 15
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3780kb
input:
3 3 CCC 5 CCCCP 4 CPCP
output:
1 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 12ms
memory: 5204kb
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