题意:一个包含()?三种字符的字符串,()符合 ,若s符合,则(s)也符合,若t符合,st也符合,问有多少对 (i,j)满足条件
贼菜啊。。
题解:这题和893D很像,都是预留一个上下界,判断是否满足条件,见代码。
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <cmath>
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 998244353
#define fuck() (cout << " ------- " << endl)
const int maxn = 1e6 + 1;
using namespace std;
int main(){
string s;
cin >> s;
int ans = 0;
int len = (int)s.length();
for(int i=0; i<len; i++){
int low = 0, up = 0;
for(int j=i; j<len; j++){
if(s[j] == '('){
low++;
up++;
}
else if(s[j] == ')'){
low--;
up--;
}
else{
low--;
up++;
}
if(up < 0) break;
if(low < 0) low = 0;
if((j - i) % 2 == 1){
if(low == 0)
ans++;
}
}
}
printf("%d\n",ans);
}