#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define fi first
#define se second
string s;
int nxt[10000000];
ii range(int L, int R){
if (L==R) return {0,0}; // ?
ii val1 = range(L+4,nxt[L+3]-1);
ii val2 = range(nxt[L+3]+1,R-1);
if (s[L+2]=='x'){
//max
return {val1.fi+val2.fi+1, min(val1.se, val2.se)};
}
//min
return {min(val1.fi, val1.se), val1.se+val2.se+1};
}
void solve(){
cin>>s; int len=s.size();
ms(nxt,-1,sizeof(nxt));
stack<int> st; int cnt=0;
FOR(i,0,len){
if (s[i]=='(') st.push(i);
if (s[i]==','){nxt[st.top()]=i; st.pop();}
if (s[i]=='?') cnt++;
}
ii ans = range(0,len-1);
cout<<cnt-ans.fi-ans.se<<'\n';
}
int main(){
//MOD=MOD1;
ios::sync_with_stdio(false);
if (fopen("input.txt", "r")) {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int TC = 1;
//cin >> TC;
FOR(i, 1, TC+1){
//cout << "Case #" << i << ": ";
solve();
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:48:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | freopen("output.txt", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
39360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
39360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
102108 KB |
Output is correct |
2 |
Correct |
84 ms |
102160 KB |
Output is correct |
3 |
Correct |
81 ms |
102068 KB |
Output is correct |
4 |
Correct |
86 ms |
102304 KB |
Output is correct |
5 |
Correct |
77 ms |
102048 KB |
Output is correct |
6 |
Correct |
81 ms |
102052 KB |
Output is correct |
7 |
Correct |
80 ms |
102132 KB |
Output is correct |
8 |
Correct |
79 ms |
102128 KB |
Output is correct |
9 |
Correct |
76 ms |
102084 KB |
Output is correct |
10 |
Correct |
79 ms |
102044 KB |
Output is correct |
11 |
Correct |
75 ms |
102044 KB |
Output is correct |
12 |
Correct |
85 ms |
102036 KB |
Output is correct |
13 |
Correct |
14 ms |
39372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
39360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
39360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |