#include <bits/stdc++.h>
using namespace std;
#define rep(i , j , k) for (int i = j; i < (int)k; i++)
#define pb push_back
#define mt make_tuple
#define all(x) x.begin(),x.end()
typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef complex<ld> point;
typedef pair<ld , ld> pld;
typedef vector<ll> vi;
inline void fileIO(string s) {
// freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
template<class T , class S>
inline bool smin(T &a, S b) { return (T)b < a ? a = b , 1 : 0; }
template<class T , class S>
inline bool smax(T &a, S b) { return a < (T)b ? a = b , 1 : 0; }
constexpr int N = 1e5 + 10;
constexpr int MOD = 1e9;
template<typename T>
inline T mod(T &v) { return v = (v % MOD + MOD) % MOD; }
template<typename S, typename T>
inline S add(S &l, T r) { return mod(l += r); }
string s;
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> s;
int n = s.size();
vector<char> vec;
for (auto e : s)
{
if (vec.size() && vec.back() == e)
vec.pop_back();
else
vec.pb(e);
}
if (vec.size()) return cout << -1 << endl, 0;
rep(i , 0 , n) {
vector<char> tmp(all(vec));
tmp.pb(s[i]);
rep(j , i + 1, n) {
auto e = s[j];
if (tmp.size() && tmp.back() == e)
tmp.pop_back();
else
tmp.pb(e);
}
if (tmp.empty()) {
cout << '(';
vec.pb(s[i]);
}
else {
auto e = s[i];
if (vec.size() && vec.back() == e)
vec.pop_back();
else
vec.pb(e);
cout << ')';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
74 ms |
560 KB |
Output is correct |
9 |
Correct |
91 ms |
508 KB |
Output is correct |
10 |
Correct |
70 ms |
384 KB |
Output is correct |
11 |
Correct |
66 ms |
384 KB |
Output is correct |
12 |
Execution timed out |
2069 ms |
888 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |