1 solutions
-
0
#include <bits/stdc++.h> using namespace std;
#define int long long string s; stack sk; int Max;
signed main() { ios::sync_with_stdio(false); cin.tie(0);
if (!(cin >> s)) return 0; sk.push(-1); for (int i = 0; i < s.size(); i++) { if (s[i] == '(' || s[i] == '[') { sk.push(i); } else { if (sk.size() > 1) { char now = s[sk.top()]; if ((now == '(' && s[i] == ')') || (now == '[' && s[i] == ']')) { sk.pop(); Max = max(Max, i - sk.top()); } else { while (!sk.empty()) sk.pop(); sk.push(i); } } else { sk.pop(); sk.push(i); } } } cout << Max << endl; return 0;}
- 1
Information
- ID
- 18289
- Time
- 10000ms
- Memory
- 1024MiB
- Difficulty
- 10
- Tags
- (None)
- # Submissions
- 1
- Accepted
- 1
- Uploaded By