답안 #824408

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
824408 2023-08-14T05:37:46 Z kwongweng Homework (CEOI22_homework) C++17
100 / 100
84 ms 83580 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[7000000]; 
/*corresponding , to each (), to split the expression into two
Main obs : all reachable values fall within a continuous interval
range returns 2 values {A,B}
A -> A smallest values cannot be reached
B -> B largest values cannot be reached
*/
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:53:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:54:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |      freopen("output.txt", "w", stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 27604 KB Output is correct
2 Correct 11 ms 27604 KB Output is correct
3 Correct 12 ms 27604 KB Output is correct
4 Correct 11 ms 27604 KB Output is correct
5 Correct 11 ms 27684 KB Output is correct
6 Correct 10 ms 27604 KB Output is correct
7 Correct 11 ms 27604 KB Output is correct
8 Correct 11 ms 27604 KB Output is correct
9 Correct 11 ms 27604 KB Output is correct
10 Correct 11 ms 27604 KB Output is correct
11 Correct 11 ms 27604 KB Output is correct
12 Correct 12 ms 27712 KB Output is correct
13 Correct 11 ms 27672 KB Output is correct
14 Correct 10 ms 27604 KB Output is correct
15 Correct 11 ms 27604 KB Output is correct
16 Correct 11 ms 27604 KB Output is correct
17 Correct 11 ms 27656 KB Output is correct
18 Correct 15 ms 27684 KB Output is correct
19 Correct 11 ms 27604 KB Output is correct
20 Correct 11 ms 27604 KB Output is correct
21 Correct 11 ms 27604 KB Output is correct
22 Correct 11 ms 27664 KB Output is correct
23 Correct 11 ms 27660 KB Output is correct
24 Correct 11 ms 27620 KB Output is correct
25 Correct 11 ms 27604 KB Output is correct
26 Correct 11 ms 27692 KB Output is correct
27 Correct 11 ms 27700 KB Output is correct
28 Correct 11 ms 27628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 27604 KB Output is correct
2 Correct 11 ms 27604 KB Output is correct
3 Correct 12 ms 27604 KB Output is correct
4 Correct 11 ms 27604 KB Output is correct
5 Correct 11 ms 27684 KB Output is correct
6 Correct 10 ms 27604 KB Output is correct
7 Correct 11 ms 27604 KB Output is correct
8 Correct 11 ms 27604 KB Output is correct
9 Correct 11 ms 27604 KB Output is correct
10 Correct 11 ms 27604 KB Output is correct
11 Correct 11 ms 27604 KB Output is correct
12 Correct 12 ms 27712 KB Output is correct
13 Correct 11 ms 27672 KB Output is correct
14 Correct 10 ms 27604 KB Output is correct
15 Correct 11 ms 27604 KB Output is correct
16 Correct 11 ms 27604 KB Output is correct
17 Correct 11 ms 27656 KB Output is correct
18 Correct 15 ms 27684 KB Output is correct
19 Correct 11 ms 27604 KB Output is correct
20 Correct 11 ms 27604 KB Output is correct
21 Correct 11 ms 27604 KB Output is correct
22 Correct 11 ms 27664 KB Output is correct
23 Correct 11 ms 27660 KB Output is correct
24 Correct 11 ms 27620 KB Output is correct
25 Correct 11 ms 27604 KB Output is correct
26 Correct 11 ms 27692 KB Output is correct
27 Correct 11 ms 27700 KB Output is correct
28 Correct 11 ms 27628 KB Output is correct
29 Correct 10 ms 27620 KB Output is correct
30 Correct 11 ms 27604 KB Output is correct
31 Correct 11 ms 27604 KB Output is correct
32 Correct 11 ms 27608 KB Output is correct
33 Correct 11 ms 27604 KB Output is correct
34 Correct 11 ms 27632 KB Output is correct
35 Correct 11 ms 27708 KB Output is correct
36 Correct 11 ms 27604 KB Output is correct
37 Correct 11 ms 27604 KB Output is correct
38 Correct 11 ms 27604 KB Output is correct
39 Correct 11 ms 27732 KB Output is correct
40 Correct 11 ms 27604 KB Output is correct
41 Correct 11 ms 27604 KB Output is correct
42 Correct 11 ms 27604 KB Output is correct
43 Correct 11 ms 27604 KB Output is correct
44 Correct 11 ms 27604 KB Output is correct
45 Correct 11 ms 27604 KB Output is correct
46 Correct 11 ms 27604 KB Output is correct
47 Correct 11 ms 27604 KB Output is correct
48 Correct 11 ms 27604 KB Output is correct
49 Correct 11 ms 27616 KB Output is correct
50 Correct 11 ms 27604 KB Output is correct
51 Correct 11 ms 27648 KB Output is correct
52 Correct 11 ms 27604 KB Output is correct
53 Correct 11 ms 27604 KB Output is correct
54 Correct 11 ms 27612 KB Output is correct
55 Correct 12 ms 27636 KB Output is correct
56 Correct 10 ms 27600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 83580 KB Output is correct
2 Correct 76 ms 83484 KB Output is correct
3 Correct 82 ms 83516 KB Output is correct
4 Correct 82 ms 83524 KB Output is correct
5 Correct 79 ms 83576 KB Output is correct
6 Correct 79 ms 83484 KB Output is correct
7 Correct 79 ms 83468 KB Output is correct
8 Correct 80 ms 83524 KB Output is correct
9 Correct 81 ms 83476 KB Output is correct
10 Correct 80 ms 83484 KB Output is correct
11 Correct 81 ms 83532 KB Output is correct
12 Correct 78 ms 83472 KB Output is correct
13 Correct 11 ms 27604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 27604 KB Output is correct
2 Correct 11 ms 27604 KB Output is correct
3 Correct 12 ms 27604 KB Output is correct
4 Correct 11 ms 27604 KB Output is correct
5 Correct 11 ms 27684 KB Output is correct
6 Correct 10 ms 27604 KB Output is correct
7 Correct 11 ms 27604 KB Output is correct
8 Correct 11 ms 27604 KB Output is correct
9 Correct 11 ms 27604 KB Output is correct
10 Correct 11 ms 27604 KB Output is correct
11 Correct 11 ms 27604 KB Output is correct
12 Correct 12 ms 27712 KB Output is correct
13 Correct 11 ms 27672 KB Output is correct
14 Correct 10 ms 27604 KB Output is correct
15 Correct 11 ms 27604 KB Output is correct
16 Correct 11 ms 27604 KB Output is correct
17 Correct 11 ms 27656 KB Output is correct
18 Correct 15 ms 27684 KB Output is correct
19 Correct 11 ms 27604 KB Output is correct
20 Correct 11 ms 27604 KB Output is correct
21 Correct 11 ms 27604 KB Output is correct
22 Correct 11 ms 27664 KB Output is correct
23 Correct 11 ms 27660 KB Output is correct
24 Correct 11 ms 27620 KB Output is correct
25 Correct 11 ms 27604 KB Output is correct
26 Correct 11 ms 27692 KB Output is correct
27 Correct 11 ms 27700 KB Output is correct
28 Correct 11 ms 27628 KB Output is correct
29 Correct 10 ms 27620 KB Output is correct
30 Correct 11 ms 27604 KB Output is correct
31 Correct 11 ms 27604 KB Output is correct
32 Correct 11 ms 27608 KB Output is correct
33 Correct 11 ms 27604 KB Output is correct
34 Correct 11 ms 27632 KB Output is correct
35 Correct 11 ms 27708 KB Output is correct
36 Correct 11 ms 27604 KB Output is correct
37 Correct 11 ms 27604 KB Output is correct
38 Correct 11 ms 27604 KB Output is correct
39 Correct 11 ms 27732 KB Output is correct
40 Correct 11 ms 27604 KB Output is correct
41 Correct 11 ms 27604 KB Output is correct
42 Correct 11 ms 27604 KB Output is correct
43 Correct 11 ms 27604 KB Output is correct
44 Correct 11 ms 27604 KB Output is correct
45 Correct 11 ms 27604 KB Output is correct
46 Correct 11 ms 27604 KB Output is correct
47 Correct 11 ms 27604 KB Output is correct
48 Correct 11 ms 27604 KB Output is correct
49 Correct 11 ms 27616 KB Output is correct
50 Correct 11 ms 27604 KB Output is correct
51 Correct 11 ms 27648 KB Output is correct
52 Correct 11 ms 27604 KB Output is correct
53 Correct 11 ms 27604 KB Output is correct
54 Correct 11 ms 27612 KB Output is correct
55 Correct 12 ms 27636 KB Output is correct
56 Correct 10 ms 27600 KB Output is correct
57 Correct 11 ms 27604 KB Output is correct
58 Correct 11 ms 27732 KB Output is correct
59 Correct 11 ms 27648 KB Output is correct
60 Correct 11 ms 27660 KB Output is correct
61 Correct 11 ms 27620 KB Output is correct
62 Correct 11 ms 27732 KB Output is correct
63 Correct 11 ms 27732 KB Output is correct
64 Correct 11 ms 27700 KB Output is correct
65 Correct 11 ms 27732 KB Output is correct
66 Correct 11 ms 27716 KB Output is correct
67 Correct 12 ms 27604 KB Output is correct
68 Correct 10 ms 27604 KB Output is correct
69 Correct 11 ms 27604 KB Output is correct
70 Correct 12 ms 27708 KB Output is correct
71 Correct 11 ms 27604 KB Output is correct
72 Correct 11 ms 27732 KB Output is correct
73 Correct 11 ms 27732 KB Output is correct
74 Correct 12 ms 27708 KB Output is correct
75 Correct 10 ms 27732 KB Output is correct
76 Correct 11 ms 27732 KB Output is correct
77 Correct 10 ms 27732 KB Output is correct
78 Correct 11 ms 27620 KB Output is correct
79 Correct 11 ms 27604 KB Output is correct
80 Correct 10 ms 27672 KB Output is correct
81 Correct 12 ms 27732 KB Output is correct
82 Correct 11 ms 27692 KB Output is correct
83 Correct 10 ms 27604 KB Output is correct
84 Correct 11 ms 27608 KB Output is correct
85 Correct 12 ms 27724 KB Output is correct
86 Correct 11 ms 27608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 27604 KB Output is correct
2 Correct 11 ms 27604 KB Output is correct
3 Correct 12 ms 27604 KB Output is correct
4 Correct 11 ms 27604 KB Output is correct
5 Correct 11 ms 27684 KB Output is correct
6 Correct 10 ms 27604 KB Output is correct
7 Correct 11 ms 27604 KB Output is correct
8 Correct 11 ms 27604 KB Output is correct
9 Correct 11 ms 27604 KB Output is correct
10 Correct 11 ms 27604 KB Output is correct
11 Correct 11 ms 27604 KB Output is correct
12 Correct 12 ms 27712 KB Output is correct
13 Correct 11 ms 27672 KB Output is correct
14 Correct 10 ms 27604 KB Output is correct
15 Correct 11 ms 27604 KB Output is correct
16 Correct 11 ms 27604 KB Output is correct
17 Correct 11 ms 27656 KB Output is correct
18 Correct 15 ms 27684 KB Output is correct
19 Correct 11 ms 27604 KB Output is correct
20 Correct 11 ms 27604 KB Output is correct
21 Correct 11 ms 27604 KB Output is correct
22 Correct 11 ms 27664 KB Output is correct
23 Correct 11 ms 27660 KB Output is correct
24 Correct 11 ms 27620 KB Output is correct
25 Correct 11 ms 27604 KB Output is correct
26 Correct 11 ms 27692 KB Output is correct
27 Correct 11 ms 27700 KB Output is correct
28 Correct 11 ms 27628 KB Output is correct
29 Correct 10 ms 27620 KB Output is correct
30 Correct 11 ms 27604 KB Output is correct
31 Correct 11 ms 27604 KB Output is correct
32 Correct 11 ms 27608 KB Output is correct
33 Correct 11 ms 27604 KB Output is correct
34 Correct 11 ms 27632 KB Output is correct
35 Correct 11 ms 27708 KB Output is correct
36 Correct 11 ms 27604 KB Output is correct
37 Correct 11 ms 27604 KB Output is correct
38 Correct 11 ms 27604 KB Output is correct
39 Correct 11 ms 27732 KB Output is correct
40 Correct 11 ms 27604 KB Output is correct
41 Correct 11 ms 27604 KB Output is correct
42 Correct 11 ms 27604 KB Output is correct
43 Correct 11 ms 27604 KB Output is correct
44 Correct 11 ms 27604 KB Output is correct
45 Correct 11 ms 27604 KB Output is correct
46 Correct 11 ms 27604 KB Output is correct
47 Correct 11 ms 27604 KB Output is correct
48 Correct 11 ms 27604 KB Output is correct
49 Correct 11 ms 27616 KB Output is correct
50 Correct 11 ms 27604 KB Output is correct
51 Correct 11 ms 27648 KB Output is correct
52 Correct 11 ms 27604 KB Output is correct
53 Correct 11 ms 27604 KB Output is correct
54 Correct 11 ms 27612 KB Output is correct
55 Correct 12 ms 27636 KB Output is correct
56 Correct 10 ms 27600 KB Output is correct
57 Correct 84 ms 83580 KB Output is correct
58 Correct 76 ms 83484 KB Output is correct
59 Correct 82 ms 83516 KB Output is correct
60 Correct 82 ms 83524 KB Output is correct
61 Correct 79 ms 83576 KB Output is correct
62 Correct 79 ms 83484 KB Output is correct
63 Correct 79 ms 83468 KB Output is correct
64 Correct 80 ms 83524 KB Output is correct
65 Correct 81 ms 83476 KB Output is correct
66 Correct 80 ms 83484 KB Output is correct
67 Correct 81 ms 83532 KB Output is correct
68 Correct 78 ms 83472 KB Output is correct
69 Correct 11 ms 27604 KB Output is correct
70 Correct 11 ms 27604 KB Output is correct
71 Correct 11 ms 27732 KB Output is correct
72 Correct 11 ms 27648 KB Output is correct
73 Correct 11 ms 27660 KB Output is correct
74 Correct 11 ms 27620 KB Output is correct
75 Correct 11 ms 27732 KB Output is correct
76 Correct 11 ms 27732 KB Output is correct
77 Correct 11 ms 27700 KB Output is correct
78 Correct 11 ms 27732 KB Output is correct
79 Correct 11 ms 27716 KB Output is correct
80 Correct 12 ms 27604 KB Output is correct
81 Correct 10 ms 27604 KB Output is correct
82 Correct 11 ms 27604 KB Output is correct
83 Correct 12 ms 27708 KB Output is correct
84 Correct 11 ms 27604 KB Output is correct
85 Correct 11 ms 27732 KB Output is correct
86 Correct 11 ms 27732 KB Output is correct
87 Correct 12 ms 27708 KB Output is correct
88 Correct 10 ms 27732 KB Output is correct
89 Correct 11 ms 27732 KB Output is correct
90 Correct 10 ms 27732 KB Output is correct
91 Correct 11 ms 27620 KB Output is correct
92 Correct 11 ms 27604 KB Output is correct
93 Correct 10 ms 27672 KB Output is correct
94 Correct 12 ms 27732 KB Output is correct
95 Correct 11 ms 27692 KB Output is correct
96 Correct 10 ms 27604 KB Output is correct
97 Correct 11 ms 27608 KB Output is correct
98 Correct 12 ms 27724 KB Output is correct
99 Correct 11 ms 27608 KB Output is correct
100 Correct 46 ms 34652 KB Output is correct
101 Correct 49 ms 34628 KB Output is correct
102 Correct 46 ms 34600 KB Output is correct
103 Correct 45 ms 34624 KB Output is correct
104 Correct 44 ms 34696 KB Output is correct
105 Correct 58 ms 50840 KB Output is correct
106 Correct 59 ms 50876 KB Output is correct
107 Correct 55 ms 50796 KB Output is correct
108 Correct 57 ms 50860 KB Output is correct
109 Correct 56 ms 50884 KB Output is correct
110 Correct 51 ms 34652 KB Output is correct
111 Correct 51 ms 34612 KB Output is correct
112 Correct 47 ms 34612 KB Output is correct
113 Correct 47 ms 34668 KB Output is correct
114 Correct 47 ms 34640 KB Output is correct
115 Correct 79 ms 83548 KB Output is correct
116 Correct 78 ms 83524 KB Output is correct
117 Correct 78 ms 83468 KB Output is correct
118 Correct 75 ms 83496 KB Output is correct
119 Correct 82 ms 83492 KB Output is correct
120 Correct 46 ms 34652 KB Output is correct
121 Correct 46 ms 34640 KB Output is correct
122 Correct 51 ms 34716 KB Output is correct
123 Correct 51 ms 34652 KB Output is correct
124 Correct 64 ms 58076 KB Output is correct
125 Correct 56 ms 58120 KB Output is correct
126 Correct 55 ms 58052 KB Output is correct
127 Correct 54 ms 58112 KB Output is correct
128 Correct 27 ms 31452 KB Output is correct
129 Correct 25 ms 31336 KB Output is correct
130 Correct 23 ms 31448 KB Output is correct
131 Correct 12 ms 27604 KB Output is correct