Submission #824402

# Submission time Handle Problem Language Result Execution time Memory
824402 2023-08-14T05:29:31 Z kwongweng Homework (CEOI22_homework) C++17
100 / 100
87 ms 102128 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define fi first
#define se second

string s;
int nxt[10000000];
ii range(int L, int R){
  if (L==R) return {0,0}; // ?
  ii val1 = range(L+4,nxt[L+3]-1);
  ii val2 = range(nxt[L+3]+1,R-1);
  if (s[L+2]=='x'){
    //max
    return {val1.fi+val2.fi+1, min(val1.se, val2.se)};
  }
  //min
  return {min(val1.fi, val2.fi), val1.se+val2.se+1};
}

void solve(){
  cin>>s; int len=s.size();
  ms(nxt,-1,sizeof(nxt));
  stack<int> st; int cnt=0;
  FOR(i,0,len){
    if (s[i]=='(') st.push(i);
    if (s[i]==','){nxt[st.top()]=i; st.pop();}
    if (s[i]=='?') cnt++;
  }
  ii ans = range(0,len-1);
  cout<<cnt-ans.fi-ans.se<<'\n';
}

int main(){
	//MOD=MOD1;
    ios::sync_with_stdio(false);
    if (fopen("input.txt", "r")) {
		  freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	  }
    int TC = 1;
    //cin >> TC; 
    FOR(i, 1, TC+1){
        //cout << "Case #" << i << ": ";
        solve();
    }
	
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:48:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |      freopen("output.txt", "w", stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 39448 KB Output is correct
2 Correct 17 ms 39332 KB Output is correct
3 Correct 16 ms 39384 KB Output is correct
4 Correct 16 ms 39376 KB Output is correct
5 Correct 19 ms 39380 KB Output is correct
6 Correct 16 ms 39360 KB Output is correct
7 Correct 16 ms 39380 KB Output is correct
8 Correct 16 ms 39364 KB Output is correct
9 Correct 15 ms 39428 KB Output is correct
10 Correct 16 ms 39464 KB Output is correct
11 Correct 15 ms 39444 KB Output is correct
12 Correct 16 ms 39380 KB Output is correct
13 Correct 16 ms 39440 KB Output is correct
14 Correct 15 ms 39416 KB Output is correct
15 Correct 15 ms 39380 KB Output is correct
16 Correct 15 ms 39380 KB Output is correct
17 Correct 16 ms 39372 KB Output is correct
18 Correct 16 ms 39380 KB Output is correct
19 Correct 16 ms 39376 KB Output is correct
20 Correct 15 ms 39416 KB Output is correct
21 Correct 16 ms 39456 KB Output is correct
22 Correct 16 ms 39380 KB Output is correct
23 Correct 16 ms 39380 KB Output is correct
24 Correct 16 ms 39380 KB Output is correct
25 Correct 16 ms 39380 KB Output is correct
26 Correct 16 ms 39392 KB Output is correct
27 Correct 18 ms 39364 KB Output is correct
28 Correct 16 ms 39448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 39448 KB Output is correct
2 Correct 17 ms 39332 KB Output is correct
3 Correct 16 ms 39384 KB Output is correct
4 Correct 16 ms 39376 KB Output is correct
5 Correct 19 ms 39380 KB Output is correct
6 Correct 16 ms 39360 KB Output is correct
7 Correct 16 ms 39380 KB Output is correct
8 Correct 16 ms 39364 KB Output is correct
9 Correct 15 ms 39428 KB Output is correct
10 Correct 16 ms 39464 KB Output is correct
11 Correct 15 ms 39444 KB Output is correct
12 Correct 16 ms 39380 KB Output is correct
13 Correct 16 ms 39440 KB Output is correct
14 Correct 15 ms 39416 KB Output is correct
15 Correct 15 ms 39380 KB Output is correct
16 Correct 15 ms 39380 KB Output is correct
17 Correct 16 ms 39372 KB Output is correct
18 Correct 16 ms 39380 KB Output is correct
19 Correct 16 ms 39376 KB Output is correct
20 Correct 15 ms 39416 KB Output is correct
21 Correct 16 ms 39456 KB Output is correct
22 Correct 16 ms 39380 KB Output is correct
23 Correct 16 ms 39380 KB Output is correct
24 Correct 16 ms 39380 KB Output is correct
25 Correct 16 ms 39380 KB Output is correct
26 Correct 16 ms 39392 KB Output is correct
27 Correct 18 ms 39364 KB Output is correct
28 Correct 16 ms 39448 KB Output is correct
29 Correct 16 ms 39372 KB Output is correct
30 Correct 17 ms 39412 KB Output is correct
31 Correct 16 ms 39368 KB Output is correct
32 Correct 14 ms 39368 KB Output is correct
33 Correct 17 ms 39432 KB Output is correct
34 Correct 16 ms 39392 KB Output is correct
35 Correct 15 ms 39432 KB Output is correct
36 Correct 16 ms 39432 KB Output is correct
37 Correct 16 ms 39380 KB Output is correct
38 Correct 15 ms 39380 KB Output is correct
39 Correct 15 ms 39368 KB Output is correct
40 Correct 15 ms 39372 KB Output is correct
41 Correct 16 ms 39380 KB Output is correct
42 Correct 16 ms 39380 KB Output is correct
43 Correct 16 ms 39380 KB Output is correct
44 Correct 15 ms 39436 KB Output is correct
45 Correct 15 ms 39364 KB Output is correct
46 Correct 16 ms 39396 KB Output is correct
47 Correct 17 ms 39380 KB Output is correct
48 Correct 17 ms 39428 KB Output is correct
49 Correct 15 ms 39412 KB Output is correct
50 Correct 16 ms 39440 KB Output is correct
51 Correct 16 ms 39380 KB Output is correct
52 Correct 16 ms 39380 KB Output is correct
53 Correct 16 ms 39380 KB Output is correct
54 Correct 16 ms 39380 KB Output is correct
55 Correct 15 ms 39380 KB Output is correct
56 Correct 16 ms 39444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 95588 KB Output is correct
2 Correct 82 ms 95680 KB Output is correct
3 Correct 85 ms 95720 KB Output is correct
4 Correct 87 ms 95712 KB Output is correct
5 Correct 82 ms 95636 KB Output is correct
6 Correct 84 ms 95708 KB Output is correct
7 Correct 82 ms 95596 KB Output is correct
8 Correct 85 ms 95720 KB Output is correct
9 Correct 84 ms 95676 KB Output is correct
10 Correct 78 ms 95592 KB Output is correct
11 Correct 83 ms 95728 KB Output is correct
12 Correct 83 ms 95556 KB Output is correct
13 Correct 15 ms 39380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 39448 KB Output is correct
2 Correct 17 ms 39332 KB Output is correct
3 Correct 16 ms 39384 KB Output is correct
4 Correct 16 ms 39376 KB Output is correct
5 Correct 19 ms 39380 KB Output is correct
6 Correct 16 ms 39360 KB Output is correct
7 Correct 16 ms 39380 KB Output is correct
8 Correct 16 ms 39364 KB Output is correct
9 Correct 15 ms 39428 KB Output is correct
10 Correct 16 ms 39464 KB Output is correct
11 Correct 15 ms 39444 KB Output is correct
12 Correct 16 ms 39380 KB Output is correct
13 Correct 16 ms 39440 KB Output is correct
14 Correct 15 ms 39416 KB Output is correct
15 Correct 15 ms 39380 KB Output is correct
16 Correct 15 ms 39380 KB Output is correct
17 Correct 16 ms 39372 KB Output is correct
18 Correct 16 ms 39380 KB Output is correct
19 Correct 16 ms 39376 KB Output is correct
20 Correct 15 ms 39416 KB Output is correct
21 Correct 16 ms 39456 KB Output is correct
22 Correct 16 ms 39380 KB Output is correct
23 Correct 16 ms 39380 KB Output is correct
24 Correct 16 ms 39380 KB Output is correct
25 Correct 16 ms 39380 KB Output is correct
26 Correct 16 ms 39392 KB Output is correct
27 Correct 18 ms 39364 KB Output is correct
28 Correct 16 ms 39448 KB Output is correct
29 Correct 16 ms 39372 KB Output is correct
30 Correct 17 ms 39412 KB Output is correct
31 Correct 16 ms 39368 KB Output is correct
32 Correct 14 ms 39368 KB Output is correct
33 Correct 17 ms 39432 KB Output is correct
34 Correct 16 ms 39392 KB Output is correct
35 Correct 15 ms 39432 KB Output is correct
36 Correct 16 ms 39432 KB Output is correct
37 Correct 16 ms 39380 KB Output is correct
38 Correct 15 ms 39380 KB Output is correct
39 Correct 15 ms 39368 KB Output is correct
40 Correct 15 ms 39372 KB Output is correct
41 Correct 16 ms 39380 KB Output is correct
42 Correct 16 ms 39380 KB Output is correct
43 Correct 16 ms 39380 KB Output is correct
44 Correct 15 ms 39436 KB Output is correct
45 Correct 15 ms 39364 KB Output is correct
46 Correct 16 ms 39396 KB Output is correct
47 Correct 17 ms 39380 KB Output is correct
48 Correct 17 ms 39428 KB Output is correct
49 Correct 15 ms 39412 KB Output is correct
50 Correct 16 ms 39440 KB Output is correct
51 Correct 16 ms 39380 KB Output is correct
52 Correct 16 ms 39380 KB Output is correct
53 Correct 16 ms 39380 KB Output is correct
54 Correct 16 ms 39380 KB Output is correct
55 Correct 15 ms 39380 KB Output is correct
56 Correct 16 ms 39444 KB Output is correct
57 Correct 18 ms 39536 KB Output is correct
58 Correct 16 ms 39380 KB Output is correct
59 Correct 15 ms 39380 KB Output is correct
60 Correct 15 ms 39464 KB Output is correct
61 Correct 15 ms 39428 KB Output is correct
62 Correct 15 ms 39376 KB Output is correct
63 Correct 14 ms 39480 KB Output is correct
64 Correct 15 ms 39380 KB Output is correct
65 Correct 15 ms 39376 KB Output is correct
66 Correct 16 ms 39380 KB Output is correct
67 Correct 16 ms 39380 KB Output is correct
68 Correct 17 ms 39352 KB Output is correct
69 Correct 16 ms 39396 KB Output is correct
70 Correct 15 ms 39380 KB Output is correct
71 Correct 19 ms 39464 KB Output is correct
72 Correct 16 ms 39508 KB Output is correct
73 Correct 15 ms 39508 KB Output is correct
74 Correct 16 ms 39508 KB Output is correct
75 Correct 16 ms 39504 KB Output is correct
76 Correct 16 ms 39424 KB Output is correct
77 Correct 17 ms 39364 KB Output is correct
78 Correct 16 ms 39476 KB Output is correct
79 Correct 15 ms 39380 KB Output is correct
80 Correct 15 ms 39368 KB Output is correct
81 Correct 16 ms 39380 KB Output is correct
82 Correct 16 ms 39380 KB Output is correct
83 Correct 17 ms 39380 KB Output is correct
84 Correct 19 ms 39464 KB Output is correct
85 Correct 17 ms 39368 KB Output is correct
86 Correct 16 ms 39432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 39448 KB Output is correct
2 Correct 17 ms 39332 KB Output is correct
3 Correct 16 ms 39384 KB Output is correct
4 Correct 16 ms 39376 KB Output is correct
5 Correct 19 ms 39380 KB Output is correct
6 Correct 16 ms 39360 KB Output is correct
7 Correct 16 ms 39380 KB Output is correct
8 Correct 16 ms 39364 KB Output is correct
9 Correct 15 ms 39428 KB Output is correct
10 Correct 16 ms 39464 KB Output is correct
11 Correct 15 ms 39444 KB Output is correct
12 Correct 16 ms 39380 KB Output is correct
13 Correct 16 ms 39440 KB Output is correct
14 Correct 15 ms 39416 KB Output is correct
15 Correct 15 ms 39380 KB Output is correct
16 Correct 15 ms 39380 KB Output is correct
17 Correct 16 ms 39372 KB Output is correct
18 Correct 16 ms 39380 KB Output is correct
19 Correct 16 ms 39376 KB Output is correct
20 Correct 15 ms 39416 KB Output is correct
21 Correct 16 ms 39456 KB Output is correct
22 Correct 16 ms 39380 KB Output is correct
23 Correct 16 ms 39380 KB Output is correct
24 Correct 16 ms 39380 KB Output is correct
25 Correct 16 ms 39380 KB Output is correct
26 Correct 16 ms 39392 KB Output is correct
27 Correct 18 ms 39364 KB Output is correct
28 Correct 16 ms 39448 KB Output is correct
29 Correct 16 ms 39372 KB Output is correct
30 Correct 17 ms 39412 KB Output is correct
31 Correct 16 ms 39368 KB Output is correct
32 Correct 14 ms 39368 KB Output is correct
33 Correct 17 ms 39432 KB Output is correct
34 Correct 16 ms 39392 KB Output is correct
35 Correct 15 ms 39432 KB Output is correct
36 Correct 16 ms 39432 KB Output is correct
37 Correct 16 ms 39380 KB Output is correct
38 Correct 15 ms 39380 KB Output is correct
39 Correct 15 ms 39368 KB Output is correct
40 Correct 15 ms 39372 KB Output is correct
41 Correct 16 ms 39380 KB Output is correct
42 Correct 16 ms 39380 KB Output is correct
43 Correct 16 ms 39380 KB Output is correct
44 Correct 15 ms 39436 KB Output is correct
45 Correct 15 ms 39364 KB Output is correct
46 Correct 16 ms 39396 KB Output is correct
47 Correct 17 ms 39380 KB Output is correct
48 Correct 17 ms 39428 KB Output is correct
49 Correct 15 ms 39412 KB Output is correct
50 Correct 16 ms 39440 KB Output is correct
51 Correct 16 ms 39380 KB Output is correct
52 Correct 16 ms 39380 KB Output is correct
53 Correct 16 ms 39380 KB Output is correct
54 Correct 16 ms 39380 KB Output is correct
55 Correct 15 ms 39380 KB Output is correct
56 Correct 16 ms 39444 KB Output is correct
57 Correct 87 ms 95588 KB Output is correct
58 Correct 82 ms 95680 KB Output is correct
59 Correct 85 ms 95720 KB Output is correct
60 Correct 87 ms 95712 KB Output is correct
61 Correct 82 ms 95636 KB Output is correct
62 Correct 84 ms 95708 KB Output is correct
63 Correct 82 ms 95596 KB Output is correct
64 Correct 85 ms 95720 KB Output is correct
65 Correct 84 ms 95676 KB Output is correct
66 Correct 78 ms 95592 KB Output is correct
67 Correct 83 ms 95728 KB Output is correct
68 Correct 83 ms 95556 KB Output is correct
69 Correct 15 ms 39380 KB Output is correct
70 Correct 18 ms 39536 KB Output is correct
71 Correct 16 ms 39380 KB Output is correct
72 Correct 15 ms 39380 KB Output is correct
73 Correct 15 ms 39464 KB Output is correct
74 Correct 15 ms 39428 KB Output is correct
75 Correct 15 ms 39376 KB Output is correct
76 Correct 14 ms 39480 KB Output is correct
77 Correct 15 ms 39380 KB Output is correct
78 Correct 15 ms 39376 KB Output is correct
79 Correct 16 ms 39380 KB Output is correct
80 Correct 16 ms 39380 KB Output is correct
81 Correct 17 ms 39352 KB Output is correct
82 Correct 16 ms 39396 KB Output is correct
83 Correct 15 ms 39380 KB Output is correct
84 Correct 19 ms 39464 KB Output is correct
85 Correct 16 ms 39508 KB Output is correct
86 Correct 15 ms 39508 KB Output is correct
87 Correct 16 ms 39508 KB Output is correct
88 Correct 16 ms 39504 KB Output is correct
89 Correct 16 ms 39424 KB Output is correct
90 Correct 17 ms 39364 KB Output is correct
91 Correct 16 ms 39476 KB Output is correct
92 Correct 15 ms 39380 KB Output is correct
93 Correct 15 ms 39368 KB Output is correct
94 Correct 16 ms 39380 KB Output is correct
95 Correct 16 ms 39380 KB Output is correct
96 Correct 17 ms 39380 KB Output is correct
97 Correct 19 ms 39464 KB Output is correct
98 Correct 17 ms 39368 KB Output is correct
99 Correct 16 ms 39432 KB Output is correct
100 Correct 57 ms 53152 KB Output is correct
101 Correct 54 ms 53192 KB Output is correct
102 Correct 50 ms 53196 KB Output is correct
103 Correct 57 ms 53152 KB Output is correct
104 Correct 57 ms 53152 KB Output is correct
105 Correct 65 ms 69536 KB Output is correct
106 Correct 67 ms 69408 KB Output is correct
107 Correct 59 ms 69428 KB Output is correct
108 Correct 62 ms 69412 KB Output is correct
109 Correct 60 ms 69420 KB Output is correct
110 Correct 56 ms 53288 KB Output is correct
111 Correct 55 ms 53164 KB Output is correct
112 Correct 51 ms 53164 KB Output is correct
113 Correct 51 ms 53168 KB Output is correct
114 Correct 51 ms 53196 KB Output is correct
115 Correct 81 ms 102128 KB Output is correct
116 Correct 80 ms 102060 KB Output is correct
117 Correct 82 ms 102044 KB Output is correct
118 Correct 79 ms 102064 KB Output is correct
119 Correct 80 ms 102052 KB Output is correct
120 Correct 50 ms 53160 KB Output is correct
121 Correct 50 ms 53152 KB Output is correct
122 Correct 53 ms 53164 KB Output is correct
123 Correct 52 ms 53188 KB Output is correct
124 Correct 58 ms 76664 KB Output is correct
125 Correct 65 ms 76720 KB Output is correct
126 Correct 56 ms 76692 KB Output is correct
127 Correct 51 ms 76704 KB Output is correct
128 Correct 31 ms 46684 KB Output is correct
129 Correct 27 ms 46676 KB Output is correct
130 Correct 28 ms 46680 KB Output is correct
131 Correct 15 ms 39384 KB Output is correct