# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
914700 |
2024-01-22T14:45:12 Z |
8pete8 |
Match (CEOI16_match) |
C++17 |
|
1 ms |
2652 KB |
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<float.h>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,ll>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
using namespace std;
#define int long long
#define double long double
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
const int mod=1e9+7,mxn=1e5,lg=30,inf=1e18,minf=-1e9,Mxn=100000;
string a;
int n;
int last[mxn+10][27];
string ans;
bool solve(int l,int r){
if(r<l)return true;
if(l==-1||r==-1||last[r][a[l]-'a']==-1)return false;
ans[l]='(';
ans[last[r][a[l]-'a']]=')';
if(!solve(l+1,last[r][a[l]-'a']-1))return false;
if(!solve(last[r][a[l]-'a']+1,r))return false;
return true;
}
int32_t main(){
cin>>a;
n=a.size();
for(int i=0;i<n;i++){
for(int j=0;j<=26;j++)last[i][j]=-1;
for(int j=0;j<=2;j++)if(i&&(last[i-1][a[i]-'a']>0))last[i][j]=last[last[i-1][a[i]-'a']-1][j];
last[i][a[i]-'a']=i;
}
ans.resize(n);
if(!solve(0,n-1))cout<<-1;
else cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |