#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 100'010;
string s;
vector<int> pos[256];
bool ans[N];
int n;
int main()
{
cin.tie(0) -> sync_with_stdio(false);
cin >> s;
n = s.size();
Loop (i,0,n)
pos[s[i]].push_back(i);
Loop (i,0,256) {
if (pos[i].size()&1) {
cout << "-1\n";
return 0;
}
Loop (j,pos[i].size()/2,pos[i].size())
ans[pos[i][j]] = 1;
}
int dep = 0;
Loop (i,0,n) {
dep += ans[i]? -1: 1;
if (dep < 0) {
cout << "-1\n";
return 0;
}
}
Loop (i,0,n)
cout << (ans[i]? ')': '(');
cout << '\n';
}
Compilation message
match.cpp: In function 'int main()':
match.cpp:21:11: warning: array subscript has type 'char' [-Wchar-subscripts]
21 | pos[s[i]].push_back(i);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |