# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1117795 |
2024-11-24T08:29:45 Z |
vjudge1 |
Match (CEOI16_match) |
C++14 |
|
1 ms |
516 KB |
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define F first
#define S second
#define ll long long
#define int ll
#define pii pair<int, int>
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define M_PI 3.14159265358979323846
#define all(v) v.begin(), v.end()
#define pss pair<string, string>
#define no cout<<"No"<<endl;
#define yes cout<<"Yes"<<endl;
#define imp cout<<-1<<endl;
#define flu cout.flush();
#define Endl endl
const int N = 100009;
const int mod = 1e9+7;
map<int, int>lm, rm;
void solve(){
string a;
cin>>a;
int n=a.size(), qwe=0, yx=0;
string test="";
stack<char>q;
for(int i=0; i<n; i++){
if(q.empty()){
test=test+"(";
q.push(a[i]);
continue;
}
char fr=q.top();
if(a[i]==fr){
test=test+")";
q.pop();
}
else{
q.push(a[i]);
test=test+"(";
}
}
for(int i=0; i<n; i++){
if(test[i]=='('){
qwe++;
}
else{
qwe--;
}
if(qwe<0){
break;
}
}
if(qwe<0 or qwe!=0){
imp;
return;
}
int l=0, r=n-1;
string left="", right="";
while(l<r){
if(lm[a[l]]!=0){
lm[a[l]]--;
left=left+")";
}
else{
lm[a[l]]++;
left=left+"(";
if(rm[a[l]]!=0){
lm[a[r]]--;
rm[a[r]]--;
}
}
if(rm[a[r]]!=0){
rm[a[r]]--;
right="("+right;
}
else{
rm[a[r]]++;
right=")"+right;
if(lm[a[r]]!=0){
lm[a[r]]--;
rm[a[r]]--;
}
}
l++;
r--;
}
cout<<left<<right<<endl;
}
signed main(){
io;
int t=1;
//cin>>t;
while(t--){
solve();
}
}
Compilation message
match.cpp: In function 'void solve()':
match.cpp:29:28: warning: unused variable 'yx' [-Wunused-variable]
29 | int n=a.size(), qwe=0, yx=0;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
516 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
516 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
516 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |