QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#636787 | #9454. String of CCPC | ucup-team5141# | WA | 4ms | 4160kb | C++20 | 2.0kb | 2024-10-13 02:52:58 | 2024-10-13 02:52:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pii pair<int,int>
using ll = long long;
using lf = long double;
int n;
bool isGod(int u, string &s){
if(s[u] != 'P')return false;
if(u - 2 < 0 )return false;
if(s[u-2] != 'C' || s[u-1] != 'C')return false;
if(u + 1 >= s.size())return false;
if(s[u+1] != 'C')return false;
return true;
}
void tc(){
string s;
cin >> n;
cin >> s;
int cnt = 0;
for(int i = 0 ; i < n ; i ++){
if(isGod(i, s))cnt ++ ;
}
for(int i = -1 ; i < n ; i ++){
// put after i.
string aux = "";
for(int j = i -3 ; j <= i ; j ++ ){
if(j >= 0 && j < n)aux += s[j];
}
aux += 'C';
for(int j = i + 1 ; j <= i + 4 ; j ++){
if(j >= 0 && j < n)aux += s[j];
}
int curPos = 0;
for(int j = i -3 ; j <= i + 4 ; j ++ ){
if(j >= 0 && j < n){
curPos ++ ;
if(isGod(j, s))continue;
if(isGod(curPos - 1, aux)){
cout << cnt + 1 << "\n";
return ;
}
}
}
aux = "";
for(int j = i -3 ; j <= i ; j ++ ){
if(j >= 0 && j < n)aux += s[j];
}
aux += 'P';
for(int j = i + 1 ; j <= i + 4 ; j ++){
if(j >= 0 && j < n)aux += s[j];
}
curPos = 0;
for(int j = i -3 ; j <= i + 4 ; j ++ ){
if(j >= 0 && j < n){
curPos ++ ;
if(isGod(j, s))continue;
if(isGod(curPos - 1, aux)){
cout << cnt + 1 << "\n";
return ;
}
}
}
}
cout << cnt << "\n";
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
freopen("in", "r", stdin);
int t;
cin >> t;
while(t--){
tc();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 4160kb
input:
3 3 CCC 5 CCCCP 4 CPCP
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 1st lines differ - expected: '1', found: '0'