이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define endl '\n'
#define forn(i, l, n) for (int i = l; i < int(n); i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
int main() // Ale C.
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("output.txt", "w", stdout);
string str;
cin >> str;
stack<char> st;
string ans = "(";
st.push(str[0]);
int test = 1;
forn(i, 1, str.length())
{
if (test < 0)
break;
if (st.empty())
{
ans += "(";
st.push(str[i]);
test++;
continue;
}
if (st.top() != str[i])
{
ans += "(";
st.push(str[i]);
test++;
}
else
{
ans += ")";
st.pop();
test--;
}
}
cout << (test == 0 ? ans : "-1");
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |