답안 #824406

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
824406 2023-08-14T05:34:23 Z kwongweng Homework (CEOI22_homework) C++17
66 / 100
97 ms 79664 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[6000000]; 
/*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 10 ms 23764 KB Output is correct
2 Correct 9 ms 23708 KB Output is correct
3 Correct 10 ms 23764 KB Output is correct
4 Correct 10 ms 23764 KB Output is correct
5 Correct 9 ms 23764 KB Output is correct
6 Correct 9 ms 23764 KB Output is correct
7 Correct 9 ms 23728 KB Output is correct
8 Correct 9 ms 23724 KB Output is correct
9 Correct 9 ms 23716 KB Output is correct
10 Correct 9 ms 23764 KB Output is correct
11 Correct 9 ms 23764 KB Output is correct
12 Correct 9 ms 23764 KB Output is correct
13 Correct 9 ms 23796 KB Output is correct
14 Correct 9 ms 23788 KB Output is correct
15 Correct 9 ms 23776 KB Output is correct
16 Correct 10 ms 23772 KB Output is correct
17 Correct 10 ms 23784 KB Output is correct
18 Correct 9 ms 23764 KB Output is correct
19 Correct 9 ms 23780 KB Output is correct
20 Correct 10 ms 23764 KB Output is correct
21 Correct 9 ms 23764 KB Output is correct
22 Correct 9 ms 23764 KB Output is correct
23 Correct 9 ms 23796 KB Output is correct
24 Correct 9 ms 23764 KB Output is correct
25 Correct 9 ms 23764 KB Output is correct
26 Correct 9 ms 23764 KB Output is correct
27 Correct 10 ms 23764 KB Output is correct
28 Correct 9 ms 23764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 9 ms 23708 KB Output is correct
3 Correct 10 ms 23764 KB Output is correct
4 Correct 10 ms 23764 KB Output is correct
5 Correct 9 ms 23764 KB Output is correct
6 Correct 9 ms 23764 KB Output is correct
7 Correct 9 ms 23728 KB Output is correct
8 Correct 9 ms 23724 KB Output is correct
9 Correct 9 ms 23716 KB Output is correct
10 Correct 9 ms 23764 KB Output is correct
11 Correct 9 ms 23764 KB Output is correct
12 Correct 9 ms 23764 KB Output is correct
13 Correct 9 ms 23796 KB Output is correct
14 Correct 9 ms 23788 KB Output is correct
15 Correct 9 ms 23776 KB Output is correct
16 Correct 10 ms 23772 KB Output is correct
17 Correct 10 ms 23784 KB Output is correct
18 Correct 9 ms 23764 KB Output is correct
19 Correct 9 ms 23780 KB Output is correct
20 Correct 10 ms 23764 KB Output is correct
21 Correct 9 ms 23764 KB Output is correct
22 Correct 9 ms 23764 KB Output is correct
23 Correct 9 ms 23796 KB Output is correct
24 Correct 9 ms 23764 KB Output is correct
25 Correct 9 ms 23764 KB Output is correct
26 Correct 9 ms 23764 KB Output is correct
27 Correct 10 ms 23764 KB Output is correct
28 Correct 9 ms 23764 KB Output is correct
29 Correct 9 ms 23764 KB Output is correct
30 Correct 9 ms 23764 KB Output is correct
31 Correct 9 ms 23764 KB Output is correct
32 Correct 9 ms 23764 KB Output is correct
33 Correct 9 ms 23764 KB Output is correct
34 Correct 9 ms 23744 KB Output is correct
35 Correct 9 ms 23792 KB Output is correct
36 Correct 10 ms 23764 KB Output is correct
37 Correct 10 ms 23800 KB Output is correct
38 Correct 9 ms 23764 KB Output is correct
39 Correct 9 ms 23764 KB Output is correct
40 Correct 9 ms 23764 KB Output is correct
41 Correct 10 ms 23764 KB Output is correct
42 Correct 9 ms 23764 KB Output is correct
43 Correct 9 ms 23764 KB Output is correct
44 Correct 9 ms 23764 KB Output is correct
45 Correct 9 ms 23764 KB Output is correct
46 Correct 12 ms 23772 KB Output is correct
47 Correct 10 ms 23764 KB Output is correct
48 Correct 10 ms 23748 KB Output is correct
49 Correct 11 ms 23768 KB Output is correct
50 Correct 11 ms 23712 KB Output is correct
51 Correct 9 ms 23764 KB Output is correct
52 Correct 9 ms 23724 KB Output is correct
53 Correct 9 ms 23764 KB Output is correct
54 Correct 9 ms 23764 KB Output is correct
55 Correct 9 ms 23768 KB Output is correct
56 Correct 9 ms 23692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 79600 KB Output is correct
2 Correct 80 ms 79572 KB Output is correct
3 Correct 80 ms 79576 KB Output is correct
4 Correct 78 ms 79632 KB Output is correct
5 Correct 78 ms 79560 KB Output is correct
6 Correct 87 ms 79656 KB Output is correct
7 Correct 82 ms 79552 KB Output is correct
8 Correct 77 ms 79664 KB Output is correct
9 Correct 79 ms 79564 KB Output is correct
10 Correct 79 ms 79572 KB Output is correct
11 Correct 83 ms 79572 KB Output is correct
12 Correct 97 ms 79560 KB Output is correct
13 Correct 11 ms 23744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 9 ms 23708 KB Output is correct
3 Correct 10 ms 23764 KB Output is correct
4 Correct 10 ms 23764 KB Output is correct
5 Correct 9 ms 23764 KB Output is correct
6 Correct 9 ms 23764 KB Output is correct
7 Correct 9 ms 23728 KB Output is correct
8 Correct 9 ms 23724 KB Output is correct
9 Correct 9 ms 23716 KB Output is correct
10 Correct 9 ms 23764 KB Output is correct
11 Correct 9 ms 23764 KB Output is correct
12 Correct 9 ms 23764 KB Output is correct
13 Correct 9 ms 23796 KB Output is correct
14 Correct 9 ms 23788 KB Output is correct
15 Correct 9 ms 23776 KB Output is correct
16 Correct 10 ms 23772 KB Output is correct
17 Correct 10 ms 23784 KB Output is correct
18 Correct 9 ms 23764 KB Output is correct
19 Correct 9 ms 23780 KB Output is correct
20 Correct 10 ms 23764 KB Output is correct
21 Correct 9 ms 23764 KB Output is correct
22 Correct 9 ms 23764 KB Output is correct
23 Correct 9 ms 23796 KB Output is correct
24 Correct 9 ms 23764 KB Output is correct
25 Correct 9 ms 23764 KB Output is correct
26 Correct 9 ms 23764 KB Output is correct
27 Correct 10 ms 23764 KB Output is correct
28 Correct 9 ms 23764 KB Output is correct
29 Correct 9 ms 23764 KB Output is correct
30 Correct 9 ms 23764 KB Output is correct
31 Correct 9 ms 23764 KB Output is correct
32 Correct 9 ms 23764 KB Output is correct
33 Correct 9 ms 23764 KB Output is correct
34 Correct 9 ms 23744 KB Output is correct
35 Correct 9 ms 23792 KB Output is correct
36 Correct 10 ms 23764 KB Output is correct
37 Correct 10 ms 23800 KB Output is correct
38 Correct 9 ms 23764 KB Output is correct
39 Correct 9 ms 23764 KB Output is correct
40 Correct 9 ms 23764 KB Output is correct
41 Correct 10 ms 23764 KB Output is correct
42 Correct 9 ms 23764 KB Output is correct
43 Correct 9 ms 23764 KB Output is correct
44 Correct 9 ms 23764 KB Output is correct
45 Correct 9 ms 23764 KB Output is correct
46 Correct 12 ms 23772 KB Output is correct
47 Correct 10 ms 23764 KB Output is correct
48 Correct 10 ms 23748 KB Output is correct
49 Correct 11 ms 23768 KB Output is correct
50 Correct 11 ms 23712 KB Output is correct
51 Correct 9 ms 23764 KB Output is correct
52 Correct 9 ms 23724 KB Output is correct
53 Correct 9 ms 23764 KB Output is correct
54 Correct 9 ms 23764 KB Output is correct
55 Correct 9 ms 23768 KB Output is correct
56 Correct 9 ms 23692 KB Output is correct
57 Correct 10 ms 23756 KB Output is correct
58 Correct 11 ms 23764 KB Output is correct
59 Correct 11 ms 23780 KB Output is correct
60 Correct 11 ms 23716 KB Output is correct
61 Correct 11 ms 23764 KB Output is correct
62 Correct 10 ms 23764 KB Output is correct
63 Correct 9 ms 23764 KB Output is correct
64 Correct 9 ms 23764 KB Output is correct
65 Correct 10 ms 23764 KB Output is correct
66 Correct 9 ms 23764 KB Output is correct
67 Correct 11 ms 23744 KB Output is correct
68 Correct 11 ms 23736 KB Output is correct
69 Correct 9 ms 23764 KB Output is correct
70 Correct 9 ms 23764 KB Output is correct
71 Correct 9 ms 23792 KB Output is correct
72 Correct 9 ms 23764 KB Output is correct
73 Correct 9 ms 23804 KB Output is correct
74 Correct 9 ms 23808 KB Output is correct
75 Correct 10 ms 23764 KB Output is correct
76 Correct 9 ms 23852 KB Output is correct
77 Correct 9 ms 23764 KB Output is correct
78 Correct 9 ms 23764 KB Output is correct
79 Correct 9 ms 23804 KB Output is correct
80 Correct 10 ms 23764 KB Output is correct
81 Correct 9 ms 23832 KB Output is correct
82 Correct 10 ms 23764 KB Output is correct
83 Correct 10 ms 23764 KB Output is correct
84 Correct 10 ms 23728 KB Output is correct
85 Correct 9 ms 23764 KB Output is correct
86 Correct 9 ms 23764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 9 ms 23708 KB Output is correct
3 Correct 10 ms 23764 KB Output is correct
4 Correct 10 ms 23764 KB Output is correct
5 Correct 9 ms 23764 KB Output is correct
6 Correct 9 ms 23764 KB Output is correct
7 Correct 9 ms 23728 KB Output is correct
8 Correct 9 ms 23724 KB Output is correct
9 Correct 9 ms 23716 KB Output is correct
10 Correct 9 ms 23764 KB Output is correct
11 Correct 9 ms 23764 KB Output is correct
12 Correct 9 ms 23764 KB Output is correct
13 Correct 9 ms 23796 KB Output is correct
14 Correct 9 ms 23788 KB Output is correct
15 Correct 9 ms 23776 KB Output is correct
16 Correct 10 ms 23772 KB Output is correct
17 Correct 10 ms 23784 KB Output is correct
18 Correct 9 ms 23764 KB Output is correct
19 Correct 9 ms 23780 KB Output is correct
20 Correct 10 ms 23764 KB Output is correct
21 Correct 9 ms 23764 KB Output is correct
22 Correct 9 ms 23764 KB Output is correct
23 Correct 9 ms 23796 KB Output is correct
24 Correct 9 ms 23764 KB Output is correct
25 Correct 9 ms 23764 KB Output is correct
26 Correct 9 ms 23764 KB Output is correct
27 Correct 10 ms 23764 KB Output is correct
28 Correct 9 ms 23764 KB Output is correct
29 Correct 9 ms 23764 KB Output is correct
30 Correct 9 ms 23764 KB Output is correct
31 Correct 9 ms 23764 KB Output is correct
32 Correct 9 ms 23764 KB Output is correct
33 Correct 9 ms 23764 KB Output is correct
34 Correct 9 ms 23744 KB Output is correct
35 Correct 9 ms 23792 KB Output is correct
36 Correct 10 ms 23764 KB Output is correct
37 Correct 10 ms 23800 KB Output is correct
38 Correct 9 ms 23764 KB Output is correct
39 Correct 9 ms 23764 KB Output is correct
40 Correct 9 ms 23764 KB Output is correct
41 Correct 10 ms 23764 KB Output is correct
42 Correct 9 ms 23764 KB Output is correct
43 Correct 9 ms 23764 KB Output is correct
44 Correct 9 ms 23764 KB Output is correct
45 Correct 9 ms 23764 KB Output is correct
46 Correct 12 ms 23772 KB Output is correct
47 Correct 10 ms 23764 KB Output is correct
48 Correct 10 ms 23748 KB Output is correct
49 Correct 11 ms 23768 KB Output is correct
50 Correct 11 ms 23712 KB Output is correct
51 Correct 9 ms 23764 KB Output is correct
52 Correct 9 ms 23724 KB Output is correct
53 Correct 9 ms 23764 KB Output is correct
54 Correct 9 ms 23764 KB Output is correct
55 Correct 9 ms 23768 KB Output is correct
56 Correct 9 ms 23692 KB Output is correct
57 Correct 81 ms 79600 KB Output is correct
58 Correct 80 ms 79572 KB Output is correct
59 Correct 80 ms 79576 KB Output is correct
60 Correct 78 ms 79632 KB Output is correct
61 Correct 78 ms 79560 KB Output is correct
62 Correct 87 ms 79656 KB Output is correct
63 Correct 82 ms 79552 KB Output is correct
64 Correct 77 ms 79664 KB Output is correct
65 Correct 79 ms 79564 KB Output is correct
66 Correct 79 ms 79572 KB Output is correct
67 Correct 83 ms 79572 KB Output is correct
68 Correct 97 ms 79560 KB Output is correct
69 Correct 11 ms 23744 KB Output is correct
70 Correct 10 ms 23756 KB Output is correct
71 Correct 11 ms 23764 KB Output is correct
72 Correct 11 ms 23780 KB Output is correct
73 Correct 11 ms 23716 KB Output is correct
74 Correct 11 ms 23764 KB Output is correct
75 Correct 10 ms 23764 KB Output is correct
76 Correct 9 ms 23764 KB Output is correct
77 Correct 9 ms 23764 KB Output is correct
78 Correct 10 ms 23764 KB Output is correct
79 Correct 9 ms 23764 KB Output is correct
80 Correct 11 ms 23744 KB Output is correct
81 Correct 11 ms 23736 KB Output is correct
82 Correct 9 ms 23764 KB Output is correct
83 Correct 9 ms 23764 KB Output is correct
84 Correct 9 ms 23792 KB Output is correct
85 Correct 9 ms 23764 KB Output is correct
86 Correct 9 ms 23804 KB Output is correct
87 Correct 9 ms 23808 KB Output is correct
88 Correct 10 ms 23764 KB Output is correct
89 Correct 9 ms 23852 KB Output is correct
90 Correct 9 ms 23764 KB Output is correct
91 Correct 9 ms 23764 KB Output is correct
92 Correct 9 ms 23804 KB Output is correct
93 Correct 10 ms 23764 KB Output is correct
94 Correct 9 ms 23832 KB Output is correct
95 Correct 10 ms 23764 KB Output is correct
96 Correct 10 ms 23764 KB Output is correct
97 Correct 10 ms 23728 KB Output is correct
98 Correct 9 ms 23764 KB Output is correct
99 Correct 9 ms 23764 KB Output is correct
100 Runtime error 60 ms 62136 KB Execution killed with signal 11
101 Halted 0 ms 0 KB -