Submission #838938

# Submission time Handle Problem Language Result Execution time Memory
838938 2023-08-28T10:02:00 Z nonono Homework (CEOI22_homework) C++14
100 / 100
262 ms 239196 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN = 5000005;

string s;
int n;

vector<vector<int>> adj(mxN);
int type[mxN];
int _min[mxN], _max[mxN];

void dfs(int u) {
    if(type[u] == -1) {
        _min[u] = 1;
        _max[u] = 1;
        return ;
    }
    
    int vL = adj[u][0];
    int vR = adj[u][1];
        
    dfs(vL);
    dfs(vR);
    
    if(type[u] == 0) {
        _min[u] = min(_min[vL], _min[vR]);
        _max[u] = _max[vL] + _max[vR];
    }
    
    if(type[u] == 1) {
        _min[u] = _min[vL] + _min[vR];
        _max[u] = min(_max[vL], _max[vR]);
    }
}

signed main() {
#define taskname ""

    if(fopen(taskname".inp", "r")) {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }

    cin.tie(0)->sync_with_stdio(0);
    
    cin >> s;
    n = s.size();
    
    vector<int> qu;
    
    int vertex = 0, node = 0;
    for(int i = 1; i <= n; i ++) {
        if(s[n - i] == ')') {
            vertex ++ ;
            qu.push_back(vertex);
        }
        
        if(s[n - i] == '?') {
            vertex ++ ;
            node ++ ;
            qu.push_back(vertex);
            type[vertex] = -1;     
        }
        
        if(s[n - i] == '(') {
            //for(int x : qu) cout << x << " "; cout << "\n";
            
            int vL = qu.back();
            qu.pop_back();
            
            int vR = qu.back();
            qu.pop_back();
            
            int u = qu.back();
            
            adj[u].push_back(vL);
            adj[u].push_back(vR);
    
            if(s.substr(n - i - 3, 3) == "min") type[u] = 0;
            if(s.substr(n - i - 3, 3) == "max") type[u] = 1;
        }
    }
    
    dfs(1);
    cout << (node - _max[1] + 1) - _min[1] + 1 << "\n";
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 49 ms 117708 KB Output is correct
2 Correct 51 ms 117756 KB Output is correct
3 Correct 52 ms 117712 KB Output is correct
4 Correct 51 ms 117744 KB Output is correct
5 Correct 59 ms 117652 KB Output is correct
6 Correct 59 ms 117652 KB Output is correct
7 Correct 58 ms 117716 KB Output is correct
8 Correct 51 ms 117636 KB Output is correct
9 Correct 52 ms 117708 KB Output is correct
10 Correct 50 ms 117708 KB Output is correct
11 Correct 51 ms 117716 KB Output is correct
12 Correct 51 ms 117624 KB Output is correct
13 Correct 50 ms 117732 KB Output is correct
14 Correct 51 ms 117716 KB Output is correct
15 Correct 59 ms 117864 KB Output is correct
16 Correct 50 ms 117724 KB Output is correct
17 Correct 50 ms 117744 KB Output is correct
18 Correct 52 ms 117680 KB Output is correct
19 Correct 52 ms 117668 KB Output is correct
20 Correct 51 ms 117676 KB Output is correct
21 Correct 50 ms 117624 KB Output is correct
22 Correct 58 ms 117740 KB Output is correct
23 Correct 57 ms 117652 KB Output is correct
24 Correct 51 ms 117672 KB Output is correct
25 Correct 51 ms 117700 KB Output is correct
26 Correct 51 ms 117708 KB Output is correct
27 Correct 49 ms 117704 KB Output is correct
28 Correct 59 ms 117708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 117708 KB Output is correct
2 Correct 51 ms 117756 KB Output is correct
3 Correct 52 ms 117712 KB Output is correct
4 Correct 51 ms 117744 KB Output is correct
5 Correct 59 ms 117652 KB Output is correct
6 Correct 59 ms 117652 KB Output is correct
7 Correct 58 ms 117716 KB Output is correct
8 Correct 51 ms 117636 KB Output is correct
9 Correct 52 ms 117708 KB Output is correct
10 Correct 50 ms 117708 KB Output is correct
11 Correct 51 ms 117716 KB Output is correct
12 Correct 51 ms 117624 KB Output is correct
13 Correct 50 ms 117732 KB Output is correct
14 Correct 51 ms 117716 KB Output is correct
15 Correct 59 ms 117864 KB Output is correct
16 Correct 50 ms 117724 KB Output is correct
17 Correct 50 ms 117744 KB Output is correct
18 Correct 52 ms 117680 KB Output is correct
19 Correct 52 ms 117668 KB Output is correct
20 Correct 51 ms 117676 KB Output is correct
21 Correct 50 ms 117624 KB Output is correct
22 Correct 58 ms 117740 KB Output is correct
23 Correct 57 ms 117652 KB Output is correct
24 Correct 51 ms 117672 KB Output is correct
25 Correct 51 ms 117700 KB Output is correct
26 Correct 51 ms 117708 KB Output is correct
27 Correct 49 ms 117704 KB Output is correct
28 Correct 59 ms 117708 KB Output is correct
29 Correct 51 ms 117696 KB Output is correct
30 Correct 53 ms 117688 KB Output is correct
31 Correct 57 ms 117748 KB Output is correct
32 Correct 60 ms 117628 KB Output is correct
33 Correct 50 ms 117668 KB Output is correct
34 Correct 51 ms 117648 KB Output is correct
35 Correct 51 ms 117684 KB Output is correct
36 Correct 51 ms 117692 KB Output is correct
37 Correct 52 ms 117728 KB Output is correct
38 Correct 53 ms 117724 KB Output is correct
39 Correct 51 ms 117716 KB Output is correct
40 Correct 51 ms 117652 KB Output is correct
41 Correct 52 ms 117692 KB Output is correct
42 Correct 52 ms 117716 KB Output is correct
43 Correct 51 ms 117660 KB Output is correct
44 Correct 52 ms 117744 KB Output is correct
45 Correct 52 ms 117716 KB Output is correct
46 Correct 58 ms 117628 KB Output is correct
47 Correct 50 ms 117624 KB Output is correct
48 Correct 51 ms 117680 KB Output is correct
49 Correct 52 ms 117744 KB Output is correct
50 Correct 51 ms 117672 KB Output is correct
51 Correct 52 ms 117708 KB Output is correct
52 Correct 51 ms 117708 KB Output is correct
53 Correct 51 ms 117748 KB Output is correct
54 Correct 50 ms 117652 KB Output is correct
55 Correct 51 ms 117700 KB Output is correct
56 Correct 52 ms 117748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 232 ms 232156 KB Output is correct
2 Correct 243 ms 238976 KB Output is correct
3 Correct 244 ms 239196 KB Output is correct
4 Correct 255 ms 239076 KB Output is correct
5 Correct 232 ms 239060 KB Output is correct
6 Correct 234 ms 239036 KB Output is correct
7 Correct 238 ms 239068 KB Output is correct
8 Correct 237 ms 238964 KB Output is correct
9 Correct 236 ms 239080 KB Output is correct
10 Correct 244 ms 239044 KB Output is correct
11 Correct 241 ms 239032 KB Output is correct
12 Correct 244 ms 239036 KB Output is correct
13 Correct 52 ms 117728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 117708 KB Output is correct
2 Correct 51 ms 117756 KB Output is correct
3 Correct 52 ms 117712 KB Output is correct
4 Correct 51 ms 117744 KB Output is correct
5 Correct 59 ms 117652 KB Output is correct
6 Correct 59 ms 117652 KB Output is correct
7 Correct 58 ms 117716 KB Output is correct
8 Correct 51 ms 117636 KB Output is correct
9 Correct 52 ms 117708 KB Output is correct
10 Correct 50 ms 117708 KB Output is correct
11 Correct 51 ms 117716 KB Output is correct
12 Correct 51 ms 117624 KB Output is correct
13 Correct 50 ms 117732 KB Output is correct
14 Correct 51 ms 117716 KB Output is correct
15 Correct 59 ms 117864 KB Output is correct
16 Correct 50 ms 117724 KB Output is correct
17 Correct 50 ms 117744 KB Output is correct
18 Correct 52 ms 117680 KB Output is correct
19 Correct 52 ms 117668 KB Output is correct
20 Correct 51 ms 117676 KB Output is correct
21 Correct 50 ms 117624 KB Output is correct
22 Correct 58 ms 117740 KB Output is correct
23 Correct 57 ms 117652 KB Output is correct
24 Correct 51 ms 117672 KB Output is correct
25 Correct 51 ms 117700 KB Output is correct
26 Correct 51 ms 117708 KB Output is correct
27 Correct 49 ms 117704 KB Output is correct
28 Correct 59 ms 117708 KB Output is correct
29 Correct 51 ms 117696 KB Output is correct
30 Correct 53 ms 117688 KB Output is correct
31 Correct 57 ms 117748 KB Output is correct
32 Correct 60 ms 117628 KB Output is correct
33 Correct 50 ms 117668 KB Output is correct
34 Correct 51 ms 117648 KB Output is correct
35 Correct 51 ms 117684 KB Output is correct
36 Correct 51 ms 117692 KB Output is correct
37 Correct 52 ms 117728 KB Output is correct
38 Correct 53 ms 117724 KB Output is correct
39 Correct 51 ms 117716 KB Output is correct
40 Correct 51 ms 117652 KB Output is correct
41 Correct 52 ms 117692 KB Output is correct
42 Correct 52 ms 117716 KB Output is correct
43 Correct 51 ms 117660 KB Output is correct
44 Correct 52 ms 117744 KB Output is correct
45 Correct 52 ms 117716 KB Output is correct
46 Correct 58 ms 117628 KB Output is correct
47 Correct 50 ms 117624 KB Output is correct
48 Correct 51 ms 117680 KB Output is correct
49 Correct 52 ms 117744 KB Output is correct
50 Correct 51 ms 117672 KB Output is correct
51 Correct 52 ms 117708 KB Output is correct
52 Correct 51 ms 117708 KB Output is correct
53 Correct 51 ms 117748 KB Output is correct
54 Correct 50 ms 117652 KB Output is correct
55 Correct 51 ms 117700 KB Output is correct
56 Correct 52 ms 117748 KB Output is correct
57 Correct 51 ms 117760 KB Output is correct
58 Correct 52 ms 117708 KB Output is correct
59 Correct 52 ms 117756 KB Output is correct
60 Correct 52 ms 117724 KB Output is correct
61 Correct 52 ms 117772 KB Output is correct
62 Correct 51 ms 117736 KB Output is correct
63 Correct 53 ms 117736 KB Output is correct
64 Correct 52 ms 117744 KB Output is correct
65 Correct 52 ms 117772 KB Output is correct
66 Correct 53 ms 117748 KB Output is correct
67 Correct 54 ms 117696 KB Output is correct
68 Correct 52 ms 117820 KB Output is correct
69 Correct 52 ms 117732 KB Output is correct
70 Correct 53 ms 117756 KB Output is correct
71 Correct 53 ms 117808 KB Output is correct
72 Correct 60 ms 117836 KB Output is correct
73 Correct 57 ms 117808 KB Output is correct
74 Correct 53 ms 117788 KB Output is correct
75 Correct 51 ms 117860 KB Output is correct
76 Correct 52 ms 117740 KB Output is correct
77 Correct 54 ms 117760 KB Output is correct
78 Correct 52 ms 117764 KB Output is correct
79 Correct 52 ms 117708 KB Output is correct
80 Correct 53 ms 117816 KB Output is correct
81 Correct 51 ms 117836 KB Output is correct
82 Correct 52 ms 117824 KB Output is correct
83 Correct 52 ms 117784 KB Output is correct
84 Correct 51 ms 117756 KB Output is correct
85 Correct 51 ms 117760 KB Output is correct
86 Correct 52 ms 117708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 117708 KB Output is correct
2 Correct 51 ms 117756 KB Output is correct
3 Correct 52 ms 117712 KB Output is correct
4 Correct 51 ms 117744 KB Output is correct
5 Correct 59 ms 117652 KB Output is correct
6 Correct 59 ms 117652 KB Output is correct
7 Correct 58 ms 117716 KB Output is correct
8 Correct 51 ms 117636 KB Output is correct
9 Correct 52 ms 117708 KB Output is correct
10 Correct 50 ms 117708 KB Output is correct
11 Correct 51 ms 117716 KB Output is correct
12 Correct 51 ms 117624 KB Output is correct
13 Correct 50 ms 117732 KB Output is correct
14 Correct 51 ms 117716 KB Output is correct
15 Correct 59 ms 117864 KB Output is correct
16 Correct 50 ms 117724 KB Output is correct
17 Correct 50 ms 117744 KB Output is correct
18 Correct 52 ms 117680 KB Output is correct
19 Correct 52 ms 117668 KB Output is correct
20 Correct 51 ms 117676 KB Output is correct
21 Correct 50 ms 117624 KB Output is correct
22 Correct 58 ms 117740 KB Output is correct
23 Correct 57 ms 117652 KB Output is correct
24 Correct 51 ms 117672 KB Output is correct
25 Correct 51 ms 117700 KB Output is correct
26 Correct 51 ms 117708 KB Output is correct
27 Correct 49 ms 117704 KB Output is correct
28 Correct 59 ms 117708 KB Output is correct
29 Correct 51 ms 117696 KB Output is correct
30 Correct 53 ms 117688 KB Output is correct
31 Correct 57 ms 117748 KB Output is correct
32 Correct 60 ms 117628 KB Output is correct
33 Correct 50 ms 117668 KB Output is correct
34 Correct 51 ms 117648 KB Output is correct
35 Correct 51 ms 117684 KB Output is correct
36 Correct 51 ms 117692 KB Output is correct
37 Correct 52 ms 117728 KB Output is correct
38 Correct 53 ms 117724 KB Output is correct
39 Correct 51 ms 117716 KB Output is correct
40 Correct 51 ms 117652 KB Output is correct
41 Correct 52 ms 117692 KB Output is correct
42 Correct 52 ms 117716 KB Output is correct
43 Correct 51 ms 117660 KB Output is correct
44 Correct 52 ms 117744 KB Output is correct
45 Correct 52 ms 117716 KB Output is correct
46 Correct 58 ms 117628 KB Output is correct
47 Correct 50 ms 117624 KB Output is correct
48 Correct 51 ms 117680 KB Output is correct
49 Correct 52 ms 117744 KB Output is correct
50 Correct 51 ms 117672 KB Output is correct
51 Correct 52 ms 117708 KB Output is correct
52 Correct 51 ms 117708 KB Output is correct
53 Correct 51 ms 117748 KB Output is correct
54 Correct 50 ms 117652 KB Output is correct
55 Correct 51 ms 117700 KB Output is correct
56 Correct 52 ms 117748 KB Output is correct
57 Correct 232 ms 232156 KB Output is correct
58 Correct 243 ms 238976 KB Output is correct
59 Correct 244 ms 239196 KB Output is correct
60 Correct 255 ms 239076 KB Output is correct
61 Correct 232 ms 239060 KB Output is correct
62 Correct 234 ms 239036 KB Output is correct
63 Correct 238 ms 239068 KB Output is correct
64 Correct 237 ms 238964 KB Output is correct
65 Correct 236 ms 239080 KB Output is correct
66 Correct 244 ms 239044 KB Output is correct
67 Correct 241 ms 239032 KB Output is correct
68 Correct 244 ms 239036 KB Output is correct
69 Correct 52 ms 117728 KB Output is correct
70 Correct 51 ms 117760 KB Output is correct
71 Correct 52 ms 117708 KB Output is correct
72 Correct 52 ms 117756 KB Output is correct
73 Correct 52 ms 117724 KB Output is correct
74 Correct 52 ms 117772 KB Output is correct
75 Correct 51 ms 117736 KB Output is correct
76 Correct 53 ms 117736 KB Output is correct
77 Correct 52 ms 117744 KB Output is correct
78 Correct 52 ms 117772 KB Output is correct
79 Correct 53 ms 117748 KB Output is correct
80 Correct 54 ms 117696 KB Output is correct
81 Correct 52 ms 117820 KB Output is correct
82 Correct 52 ms 117732 KB Output is correct
83 Correct 53 ms 117756 KB Output is correct
84 Correct 53 ms 117808 KB Output is correct
85 Correct 60 ms 117836 KB Output is correct
86 Correct 57 ms 117808 KB Output is correct
87 Correct 53 ms 117788 KB Output is correct
88 Correct 51 ms 117860 KB Output is correct
89 Correct 52 ms 117740 KB Output is correct
90 Correct 54 ms 117760 KB Output is correct
91 Correct 52 ms 117764 KB Output is correct
92 Correct 52 ms 117708 KB Output is correct
93 Correct 53 ms 117816 KB Output is correct
94 Correct 51 ms 117836 KB Output is correct
95 Correct 52 ms 117824 KB Output is correct
96 Correct 52 ms 117784 KB Output is correct
97 Correct 51 ms 117756 KB Output is correct
98 Correct 51 ms 117760 KB Output is correct
99 Correct 52 ms 117708 KB Output is correct
100 Correct 242 ms 186124 KB Output is correct
101 Correct 262 ms 186236 KB Output is correct
102 Correct 229 ms 186156 KB Output is correct
103 Correct 242 ms 186132 KB Output is correct
104 Correct 240 ms 186228 KB Output is correct
105 Correct 232 ms 203756 KB Output is correct
106 Correct 238 ms 203860 KB Output is correct
107 Correct 230 ms 203784 KB Output is correct
108 Correct 228 ms 203724 KB Output is correct
109 Correct 232 ms 203840 KB Output is correct
110 Correct 240 ms 186152 KB Output is correct
111 Correct 252 ms 186132 KB Output is correct
112 Correct 233 ms 186232 KB Output is correct
113 Correct 234 ms 186188 KB Output is correct
114 Correct 242 ms 186152 KB Output is correct
115 Correct 245 ms 238972 KB Output is correct
116 Correct 247 ms 239196 KB Output is correct
117 Correct 240 ms 239028 KB Output is correct
118 Correct 239 ms 239036 KB Output is correct
119 Correct 240 ms 239004 KB Output is correct
120 Correct 235 ms 186196 KB Output is correct
121 Correct 238 ms 186320 KB Output is correct
122 Correct 241 ms 186192 KB Output is correct
123 Correct 246 ms 186160 KB Output is correct
124 Correct 228 ms 211904 KB Output is correct
125 Correct 227 ms 211656 KB Output is correct
126 Correct 236 ms 211648 KB Output is correct
127 Correct 235 ms 211644 KB Output is correct
128 Correct 142 ms 153612 KB Output is correct
129 Correct 140 ms 153540 KB Output is correct
130 Correct 142 ms 153680 KB Output is correct
131 Correct 51 ms 117724 KB Output is correct