QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#636803 | #9454. String of CCPC | ucup-team5141# | WA | 37ms | 3992kb | C++20 | 2.3kb | 2024-10-13 03:01:12 | 2024-10-13 03:01:12 |
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 = "";
auto test = [&] (){
int curPos = 0;
for(int j = i -3 ; j <= i ; j ++ ){
if(j >= 0 && j < n){
if(!isGod(j, s) && isGod(curPos, aux)){
cout << cnt + 1 << "\n";
return true;
}
curPos ++ ;
}
}
if(isGod(curPos, aux)){
cout << cnt + 1 << "\n";
return true;
}
curPos ++ ;
for(int j = i +1 ; j <= i + 4 ; j ++ ){
if(j >= 0 && j < n){
if(!isGod(j, s) && isGod(curPos, aux)){
cout << cnt + 1 << "\n";
return true;
}
curPos ++ ;
}
}
return false;
};
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];
}
if(test())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];
}
if(test()) return ;
}
cout << cnt << "\n";
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int t;
cin >> t;
while(t--){
tc();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3492kb
input:
3 3 CCC 5 CCCCP 4 CPCP
output:
1 1 1
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 37ms
memory: 3992kb
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 2 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 2 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:
wrong answer 87th lines differ - expected: '1', found: '2'