# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
712368 |
2023-03-18T16:56:45 Z |
yuseok0803 |
Match (CEOI16_match) |
C++14 |
|
19 ms |
13872 KB |
#include <stdio.h>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stack>
#include <ctype.h>
#define p(x,y) pair<x, y>
#define pii pair<int, int>
#define v(x) vector<x>
#define q(x) queue<x>
#define pq(x) priority_queue<x>
#define uppq(x, comp) priority_queue<x, vector<x>, comp>
#define st(x) set<x>
#define m(x, y) map<x, y>
#define fi(s,e) for(int i=s;i<e;i++)
#define fj(s,e) for(int j=s;j<e;j++)
#define fk(s,e) for(int k=s;k<e;k++)
typedef long long int ll;
typedef unsigned long long int ull;
typedef __int128 ulll;
using namespace std;
int dp[100010][30];
char s[100010];
char ans[100010];
int chk;
void find(int l, int r){
if(l>r) return;
if(dp[r][s[l]-'a'] <= l){
chk=-1;
return;
}
int mid = dp[r][s[l]-'a'];
ans[l]='(';
ans[mid]=')';
find(l+1, mid-1);
find(mid+1, r);
return;
}
int main(void){
scanf("%s",s);
int l = strlen(s);
fi(0,l){
fj(0,'z'-'a'+1){
dp[i][j]=-1;
if(s[i]-'a' == j) dp[i][j]=i;
if(i && dp[i-1][s[i]-'a'] > 0) dp[i][j] = max(dp[i][j], dp[dp[i-1][s[i]-'a']-1][j]);
}
}
find(0,l-1);
if(chk==-1){printf("-1\n");return 0;}
fi(0,l) printf("%c",ans[i]);
printf("\n");
return 0;
}
Compilation message
match.cpp: In function 'int main()':
match.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | scanf("%s",s);
| ~~~~~^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
432 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
432 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
556 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
2 ms |
1236 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
11 |
Correct |
1 ms |
1236 KB |
Output is correct |
12 |
Correct |
9 ms |
8520 KB |
Output is correct |
13 |
Correct |
11 ms |
9172 KB |
Output is correct |
14 |
Correct |
12 ms |
10240 KB |
Output is correct |
15 |
Correct |
14 ms |
11960 KB |
Output is correct |
16 |
Correct |
13 ms |
11960 KB |
Output is correct |
17 |
Correct |
19 ms |
12592 KB |
Output is correct |
18 |
Correct |
17 ms |
11928 KB |
Output is correct |
19 |
Correct |
18 ms |
13012 KB |
Output is correct |
20 |
Correct |
10 ms |
8748 KB |
Output is correct |
21 |
Correct |
19 ms |
13872 KB |
Output is correct |