Submission #58115

# Submission time Handle Problem Language Result Execution time Memory
58115 2018-07-16T21:22:56 Z ksun48 Security Gate (JOI18_security_gate) C++14
30 / 100
5000 ms 996 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const LL MOD = 1000000007;
const int MAXN = 110;
LL check_slow(string s){
	vector<int> psums(1,0);
	for(int j = 0; j < s.size(); j++){
		if(s[j] == '('){
			psums.push_back(psums[psums.size() - 1] + 1);
		} else {
			psums.push_back(psums[psums.size() - 1] - 1);			
		}
	}
	int laste = psums.size() - 1;
	while(laste > 0 && psums[laste-1] >= psums[psums.size()-1]){
		laste--;
	}
	vector<int> endlists[2 * MAXN];
	vector<int> psumlists[2 * MAXN];
	int ecuridx[2 * MAXN];
	int pcuridx[2 * MAXN];
	for(int j = laste; j <= psums.size() - 1; j++){
		endlists[MAXN + psums[j]].push_back(j);
		ecuridx[MAXN + psums[j]] = 0;
	}
	for(int j = 0; j <= psums.size() - 1; j++){
		psumlists[MAXN + psums[j]].push_back(j);
		pcuridx[MAXN + psums[j]] = 0;
	}
	int a = psums[psums.size() - 1] / 2;
	for(int j = 0; j < psums.size(); j++){
		if(psums[j] < 0) break;
		int need = psums[j] + a;
		int idx = ecuridx[MAXN + need];
		if(idx < endlists[MAXN + need].size()){
			int e = endlists[MAXN + need][idx];
			// check if all elements in [j,e] are <=
			int idx2 = pcuridx[MAXN + 2 * psums[j] + 1];
			if(idx2 < psumlists[MAXN + 2 * psums[j] + 1].size() && psumlists[MAXN + 2 * psums[j] + 1][idx2] <= e){
			} else {
				return 1;
			}
		}
		if(j >= laste){
			ecuridx[MAXN + psums[j]]++;
		}
		pcuridx[MAXN + psums[j]]++;
	}
	return 0;
}

LL check(string s){
	vector<int> psums(1,0);
	for(int j = 0; j < s.size(); j++){
		if(s[j] == '('){
			psums.push_back(psums[psums.size() - 1] + 1);
		} else {
			psums.push_back(psums[psums.size() - 1] - 1);			
		}
	}
	int laste = psums.size() - 1;
	while(laste > 0 && psums[laste - 1] >= psums[psums.size() - 1]){
		laste--;
	}
	int lasts = 0;
	while(lasts + 1 < psums.size() && psums[lasts + 1] >= psums[0]){
		lasts++;
	}
	int minv = 0;
	int maxv = 0;
	int a = psums[psums.size()-1] / 2;
	for(int i = 0; i < psums.size(); i++){
		if(i <= lasts){
			minv = min(minv, max(0,psums[i]));
			maxv = max(maxv, psums[i]);
		}
		while(minv <= maxv && minv * 2 < psums[i]) minv++;
		if(i >= laste){
			int b = psums[i]-a;
			if(b >= minv && b <= maxv) return 1;
		}
	}
	return 0;
}

LL cnt(string s, int idx){
	if(idx == s.size()){
		return check(s);
	}
	if(s[idx] != 'x'){
		return cnt(s, idx + 1);
	}
	string s1 = s;
	string s2 = s;
	s1[idx] = '(';
	s2[idx] = ')';
	for(int z = idx + 1; z <= s.size(); z++){
		if(z == s.size() || s[z] == 'x'){
			return (cnt(s1, z) + cnt(s2, z)) % MOD;
		}
	}
}
int main(){
	int n;
	string s;
	cin >> n >> s;
	if(n % 2 == 1){
		cout << 0 << '\n';
		return 0;
	}
	cout << cnt(s, 0) << '\n';
}

Compilation message

securitygate.cpp: In function 'LL check_slow(std::__cxx11::string)':
securitygate.cpp:9:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 0; j < s.size(); j++){
                 ~~^~~~~~~~~~
securitygate.cpp:24:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = laste; j <= psums.size() - 1; j++){
                     ~~^~~~~~~~~~~~~~~~~~~
securitygate.cpp:28:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 0; j <= psums.size() - 1; j++){
                 ~~^~~~~~~~~~~~~~~~~~~
securitygate.cpp:33:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 0; j < psums.size(); j++){
                 ~~^~~~~~~~~~~~~~
securitygate.cpp:37:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(idx < endlists[MAXN + need].size()){
      ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
securitygate.cpp:41:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(idx2 < psumlists[MAXN + 2 * psums[j] + 1].size() && psumlists[MAXN + 2 * psums[j] + 1][idx2] <= e){
       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
securitygate.cpp: In function 'LL check(std::__cxx11::string)':
securitygate.cpp:56:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 0; j < s.size(); j++){
                 ~~^~~~~~~~~~
securitygate.cpp:68:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(lasts + 1 < psums.size() && psums[lasts + 1] >= psums[0]){
        ~~~~~~~~~~^~~~~~~~~~~~~~
securitygate.cpp:74:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < psums.size(); i++){
                 ~~^~~~~~~~~~~~~~
securitygate.cpp: In function 'LL cnt(std::__cxx11::string, int)':
securitygate.cpp:89:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(idx == s.size()){
     ~~~~^~~~~~~~~~~
securitygate.cpp:99:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int z = idx + 1; z <= s.size(); z++){
                       ~~^~~~~~~~~~~
securitygate.cpp:100:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(z == s.size() || s[z] == 'x'){
      ~~^~~~~~~~~~~
securitygate.cpp:104:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 564 KB Output is correct
6 Correct 2 ms 584 KB Output is correct
7 Correct 2 ms 584 KB Output is correct
8 Correct 2 ms 584 KB Output is correct
9 Correct 4 ms 584 KB Output is correct
10 Correct 2 ms 584 KB Output is correct
11 Correct 2 ms 584 KB Output is correct
12 Correct 3 ms 664 KB Output is correct
13 Correct 2 ms 664 KB Output is correct
14 Correct 2 ms 664 KB Output is correct
15 Correct 3 ms 676 KB Output is correct
16 Correct 3 ms 680 KB Output is correct
17 Correct 3 ms 840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 564 KB Output is correct
6 Correct 2 ms 584 KB Output is correct
7 Correct 2 ms 584 KB Output is correct
8 Correct 2 ms 584 KB Output is correct
9 Correct 4 ms 584 KB Output is correct
10 Correct 2 ms 584 KB Output is correct
11 Correct 2 ms 584 KB Output is correct
12 Correct 3 ms 664 KB Output is correct
13 Correct 2 ms 664 KB Output is correct
14 Correct 2 ms 664 KB Output is correct
15 Correct 3 ms 676 KB Output is correct
16 Correct 3 ms 680 KB Output is correct
17 Correct 3 ms 840 KB Output is correct
18 Correct 3 ms 840 KB Output is correct
19 Correct 2 ms 840 KB Output is correct
20 Correct 7 ms 840 KB Output is correct
21 Correct 15 ms 840 KB Output is correct
22 Correct 12 ms 840 KB Output is correct
23 Correct 3 ms 840 KB Output is correct
24 Correct 10 ms 840 KB Output is correct
25 Correct 2 ms 840 KB Output is correct
26 Correct 4 ms 840 KB Output is correct
27 Correct 9 ms 840 KB Output is correct
28 Correct 7 ms 840 KB Output is correct
29 Correct 3 ms 840 KB Output is correct
30 Correct 3 ms 840 KB Output is correct
31 Correct 10 ms 840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 564 KB Output is correct
6 Correct 2 ms 584 KB Output is correct
7 Correct 2 ms 584 KB Output is correct
8 Correct 2 ms 584 KB Output is correct
9 Correct 4 ms 584 KB Output is correct
10 Correct 2 ms 584 KB Output is correct
11 Correct 2 ms 584 KB Output is correct
12 Correct 3 ms 664 KB Output is correct
13 Correct 2 ms 664 KB Output is correct
14 Correct 2 ms 664 KB Output is correct
15 Correct 3 ms 676 KB Output is correct
16 Correct 3 ms 680 KB Output is correct
17 Correct 3 ms 840 KB Output is correct
18 Correct 3 ms 840 KB Output is correct
19 Correct 2 ms 840 KB Output is correct
20 Correct 7 ms 840 KB Output is correct
21 Correct 15 ms 840 KB Output is correct
22 Correct 12 ms 840 KB Output is correct
23 Correct 3 ms 840 KB Output is correct
24 Correct 10 ms 840 KB Output is correct
25 Correct 2 ms 840 KB Output is correct
26 Correct 4 ms 840 KB Output is correct
27 Correct 9 ms 840 KB Output is correct
28 Correct 7 ms 840 KB Output is correct
29 Correct 3 ms 840 KB Output is correct
30 Correct 3 ms 840 KB Output is correct
31 Correct 10 ms 840 KB Output is correct
32 Correct 60 ms 840 KB Output is correct
33 Correct 16 ms 840 KB Output is correct
34 Correct 1109 ms 840 KB Output is correct
35 Correct 47 ms 840 KB Output is correct
36 Correct 95 ms 840 KB Output is correct
37 Correct 415 ms 840 KB Output is correct
38 Correct 1773 ms 840 KB Output is correct
39 Correct 46 ms 840 KB Output is correct
40 Correct 1405 ms 840 KB Output is correct
41 Correct 1620 ms 928 KB Output is correct
42 Correct 1541 ms 944 KB Output is correct
43 Correct 890 ms 984 KB Output is correct
44 Correct 118 ms 984 KB Output is correct
45 Correct 1786 ms 996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 564 KB Output is correct
6 Correct 2 ms 584 KB Output is correct
7 Correct 2 ms 584 KB Output is correct
8 Correct 2 ms 584 KB Output is correct
9 Correct 4 ms 584 KB Output is correct
10 Correct 2 ms 584 KB Output is correct
11 Correct 2 ms 584 KB Output is correct
12 Correct 3 ms 664 KB Output is correct
13 Correct 2 ms 664 KB Output is correct
14 Correct 2 ms 664 KB Output is correct
15 Correct 3 ms 676 KB Output is correct
16 Correct 3 ms 680 KB Output is correct
17 Correct 3 ms 840 KB Output is correct
18 Correct 3 ms 840 KB Output is correct
19 Correct 2 ms 840 KB Output is correct
20 Correct 7 ms 840 KB Output is correct
21 Correct 15 ms 840 KB Output is correct
22 Correct 12 ms 840 KB Output is correct
23 Correct 3 ms 840 KB Output is correct
24 Correct 10 ms 840 KB Output is correct
25 Correct 2 ms 840 KB Output is correct
26 Correct 4 ms 840 KB Output is correct
27 Correct 9 ms 840 KB Output is correct
28 Correct 7 ms 840 KB Output is correct
29 Correct 3 ms 840 KB Output is correct
30 Correct 3 ms 840 KB Output is correct
31 Correct 10 ms 840 KB Output is correct
32 Correct 60 ms 840 KB Output is correct
33 Correct 16 ms 840 KB Output is correct
34 Correct 1109 ms 840 KB Output is correct
35 Correct 47 ms 840 KB Output is correct
36 Correct 95 ms 840 KB Output is correct
37 Correct 415 ms 840 KB Output is correct
38 Correct 1773 ms 840 KB Output is correct
39 Correct 46 ms 840 KB Output is correct
40 Correct 1405 ms 840 KB Output is correct
41 Correct 1620 ms 928 KB Output is correct
42 Correct 1541 ms 944 KB Output is correct
43 Correct 890 ms 984 KB Output is correct
44 Correct 118 ms 984 KB Output is correct
45 Correct 1786 ms 996 KB Output is correct
46 Correct 2 ms 996 KB Output is correct
47 Correct 2 ms 996 KB Output is correct
48 Correct 3 ms 996 KB Output is correct
49 Execution timed out 5013 ms 996 KB Time limit exceeded
50 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 564 KB Output is correct
6 Correct 2 ms 584 KB Output is correct
7 Correct 2 ms 584 KB Output is correct
8 Correct 2 ms 584 KB Output is correct
9 Correct 4 ms 584 KB Output is correct
10 Correct 2 ms 584 KB Output is correct
11 Correct 2 ms 584 KB Output is correct
12 Correct 3 ms 664 KB Output is correct
13 Correct 2 ms 664 KB Output is correct
14 Correct 2 ms 664 KB Output is correct
15 Correct 3 ms 676 KB Output is correct
16 Correct 3 ms 680 KB Output is correct
17 Correct 3 ms 840 KB Output is correct
18 Correct 3 ms 840 KB Output is correct
19 Correct 2 ms 840 KB Output is correct
20 Correct 7 ms 840 KB Output is correct
21 Correct 15 ms 840 KB Output is correct
22 Correct 12 ms 840 KB Output is correct
23 Correct 3 ms 840 KB Output is correct
24 Correct 10 ms 840 KB Output is correct
25 Correct 2 ms 840 KB Output is correct
26 Correct 4 ms 840 KB Output is correct
27 Correct 9 ms 840 KB Output is correct
28 Correct 7 ms 840 KB Output is correct
29 Correct 3 ms 840 KB Output is correct
30 Correct 3 ms 840 KB Output is correct
31 Correct 10 ms 840 KB Output is correct
32 Correct 60 ms 840 KB Output is correct
33 Correct 16 ms 840 KB Output is correct
34 Correct 1109 ms 840 KB Output is correct
35 Correct 47 ms 840 KB Output is correct
36 Correct 95 ms 840 KB Output is correct
37 Correct 415 ms 840 KB Output is correct
38 Correct 1773 ms 840 KB Output is correct
39 Correct 46 ms 840 KB Output is correct
40 Correct 1405 ms 840 KB Output is correct
41 Correct 1620 ms 928 KB Output is correct
42 Correct 1541 ms 944 KB Output is correct
43 Correct 890 ms 984 KB Output is correct
44 Correct 118 ms 984 KB Output is correct
45 Correct 1786 ms 996 KB Output is correct
46 Correct 2 ms 996 KB Output is correct
47 Correct 2 ms 996 KB Output is correct
48 Correct 3 ms 996 KB Output is correct
49 Execution timed out 5013 ms 996 KB Time limit exceeded
50 Halted 0 ms 0 KB -