Submission #63161

# Submission time Handle Problem Language Result Execution time Memory
63161 2018-08-01T01:33:26 Z khsoo01 Match (CEOI16_match) C++11
100 / 100
22 ms 12652 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
 
int n, dt[N][26];
char a[N], b[N];
 
void solve (int S, int E) {
	if(S>E) return;
	int T = dt[E][a[S]];
	if(T <= S) {
		puts("-1");
		exit(0);
	}
	b[S] = '(';
	b[T] = ')';
	solve(S+1, T-1);
	solve(T+1, E);
}
 
int main()
{
	scanf("%s",a+1);
	n = strlen(a+1);
	for(int i=1;i<=n;i++) {
		a[i] -= 'a';
		if(i == 1 || dt[i-1][a[i]] < 2) {
			for(int j=0;j<26;j++) {
				dt[i][j] = -1;
			}
		}
		else {
			int T = dt[i-1][a[i]] - 1;
			for(int j=0;j<26;j++) {
				dt[i][j] = dt[T][j];
			}
		}
		dt[i][a[i]] = i;
	}
	solve(1, n);
	printf("%s",b+1);
}

Compilation message

match.cpp: In function 'void solve(int, int)':
match.cpp:10:20: warning: array subscript has type 'char' [-Wchar-subscripts]
  int T = dt[E][a[S]];
                    ^
match.cpp: In function 'int main()':
match.cpp:27:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   if(i == 1 || dt[i-1][a[i]] < 2) {
                            ^
match.cpp:33:24: warning: array subscript has type 'char' [-Wchar-subscripts]
    int T = dt[i-1][a[i]] - 1;
                        ^
match.cpp:38:13: warning: array subscript has type 'char' [-Wchar-subscripts]
   dt[i][a[i]] = i;
             ^
match.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",a+1);
  ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 420 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 3 ms 628 KB Output is correct
7 Correct 4 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 420 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 3 ms 628 KB Output is correct
7 Correct 4 ms 760 KB Output is correct
8 Correct 4 ms 1224 KB Output is correct
9 Correct 5 ms 1356 KB Output is correct
10 Correct 6 ms 1380 KB Output is correct
11 Correct 4 ms 1448 KB Output is correct
12 Correct 14 ms 7496 KB Output is correct
13 Correct 15 ms 8188 KB Output is correct
14 Correct 15 ms 8892 KB Output is correct
15 Correct 19 ms 10372 KB Output is correct
16 Correct 19 ms 10372 KB Output is correct
17 Correct 19 ms 11036 KB Output is correct
18 Correct 19 ms 11036 KB Output is correct
19 Correct 19 ms 11788 KB Output is correct
20 Correct 15 ms 11788 KB Output is correct
21 Correct 22 ms 12652 KB Output is correct