# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1117845 |
2024-11-24T08:53:43 Z |
vjudge1 |
Match (CEOI16_match) |
C++17 |
|
1 ms |
336 KB |
// Author RufatM
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e9+7
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define pb push_back
#define pii pair<ll,int>
#define all(a) a.begin(),a.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main(){
int t=1;
//cin >> t;
while(t--){
fastio;
string S;
cin >> S;
int N = S.length();
vector<char> B(N);
stack<pair<char,int>> st;
for(int i = 0; i < N; i++) {
char c = S[i];
if(!st.empty() && st.top().first == c) {
B[st.top().second] = '(';
B[i] = ')';
st.pop();
} else {
st.push({c, i});
}
}
if(!st.empty()) {
cout << "-1\n";
return 0;
}
int balance = 0;
for(int i = 0; i < N; i++) {
if(B[i] == '(') balance++;
else if(B[i] == ')') balance--;
else {
cout << "-1\n";
return 0;
}
if(balance < 0) {
cout << "-1\n";
return 0;
}
}
if(balance != 0) {
cout << "-1\n";
return 0;
}
for(int i = 0; i < N; i++) {
cout << B[i];
}
cout << '\n';
}
}
//Allahim insallah tle vermez
//Yasasin Yaxsi Kiwiler
//Yasasin Info Azerbaijan
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |