Submission #838934

# Submission time Handle Problem Language Result Execution time Memory
838934 2023-08-28T09:52:58 Z nonono Homework (CEOI22_homework) C++14
53 / 100
63 ms 92908 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN = 1000005;

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 12 ms 23764 KB Output is correct
2 Correct 11 ms 23740 KB Output is correct
3 Correct 12 ms 23836 KB Output is correct
4 Correct 12 ms 23824 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 12 ms 23712 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 11 ms 23792 KB Output is correct
9 Correct 11 ms 23724 KB Output is correct
10 Correct 12 ms 23812 KB Output is correct
11 Correct 11 ms 23816 KB Output is correct
12 Correct 11 ms 23740 KB Output is correct
13 Correct 11 ms 23808 KB Output is correct
14 Correct 11 ms 23764 KB Output is correct
15 Correct 11 ms 23824 KB Output is correct
16 Correct 11 ms 23820 KB Output is correct
17 Correct 11 ms 23776 KB Output is correct
18 Correct 12 ms 23736 KB Output is correct
19 Correct 12 ms 23824 KB Output is correct
20 Correct 12 ms 23824 KB Output is correct
21 Correct 12 ms 23776 KB Output is correct
22 Correct 11 ms 23764 KB Output is correct
23 Correct 11 ms 23828 KB Output is correct
24 Correct 11 ms 23828 KB Output is correct
25 Correct 13 ms 23824 KB Output is correct
26 Correct 11 ms 23764 KB Output is correct
27 Correct 11 ms 23828 KB Output is correct
28 Correct 12 ms 23828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 11 ms 23740 KB Output is correct
3 Correct 12 ms 23836 KB Output is correct
4 Correct 12 ms 23824 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 12 ms 23712 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 11 ms 23792 KB Output is correct
9 Correct 11 ms 23724 KB Output is correct
10 Correct 12 ms 23812 KB Output is correct
11 Correct 11 ms 23816 KB Output is correct
12 Correct 11 ms 23740 KB Output is correct
13 Correct 11 ms 23808 KB Output is correct
14 Correct 11 ms 23764 KB Output is correct
15 Correct 11 ms 23824 KB Output is correct
16 Correct 11 ms 23820 KB Output is correct
17 Correct 11 ms 23776 KB Output is correct
18 Correct 12 ms 23736 KB Output is correct
19 Correct 12 ms 23824 KB Output is correct
20 Correct 12 ms 23824 KB Output is correct
21 Correct 12 ms 23776 KB Output is correct
22 Correct 11 ms 23764 KB Output is correct
23 Correct 11 ms 23828 KB Output is correct
24 Correct 11 ms 23828 KB Output is correct
25 Correct 13 ms 23824 KB Output is correct
26 Correct 11 ms 23764 KB Output is correct
27 Correct 11 ms 23828 KB Output is correct
28 Correct 12 ms 23828 KB Output is correct
29 Correct 11 ms 23824 KB Output is correct
30 Correct 11 ms 23820 KB Output is correct
31 Correct 11 ms 23828 KB Output is correct
32 Correct 11 ms 23816 KB Output is correct
33 Correct 12 ms 23824 KB Output is correct
34 Correct 11 ms 23752 KB Output is correct
35 Correct 11 ms 23828 KB Output is correct
36 Correct 12 ms 23764 KB Output is correct
37 Correct 11 ms 23828 KB Output is correct
38 Correct 12 ms 23736 KB Output is correct
39 Correct 13 ms 23796 KB Output is correct
40 Correct 12 ms 23796 KB Output is correct
41 Correct 11 ms 23800 KB Output is correct
42 Correct 12 ms 23764 KB Output is correct
43 Correct 14 ms 23824 KB Output is correct
44 Correct 11 ms 23828 KB Output is correct
45 Correct 11 ms 23720 KB Output is correct
46 Correct 11 ms 23748 KB Output is correct
47 Correct 11 ms 23828 KB Output is correct
48 Correct 12 ms 23764 KB Output is correct
49 Correct 12 ms 23768 KB Output is correct
50 Correct 11 ms 23832 KB Output is correct
51 Correct 11 ms 23764 KB Output is correct
52 Correct 11 ms 23764 KB Output is correct
53 Correct 11 ms 23824 KB Output is correct
54 Correct 12 ms 23824 KB Output is correct
55 Correct 11 ms 23764 KB Output is correct
56 Correct 12 ms 23712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 63 ms 92908 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 11 ms 23740 KB Output is correct
3 Correct 12 ms 23836 KB Output is correct
4 Correct 12 ms 23824 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 12 ms 23712 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 11 ms 23792 KB Output is correct
9 Correct 11 ms 23724 KB Output is correct
10 Correct 12 ms 23812 KB Output is correct
11 Correct 11 ms 23816 KB Output is correct
12 Correct 11 ms 23740 KB Output is correct
13 Correct 11 ms 23808 KB Output is correct
14 Correct 11 ms 23764 KB Output is correct
15 Correct 11 ms 23824 KB Output is correct
16 Correct 11 ms 23820 KB Output is correct
17 Correct 11 ms 23776 KB Output is correct
18 Correct 12 ms 23736 KB Output is correct
19 Correct 12 ms 23824 KB Output is correct
20 Correct 12 ms 23824 KB Output is correct
21 Correct 12 ms 23776 KB Output is correct
22 Correct 11 ms 23764 KB Output is correct
23 Correct 11 ms 23828 KB Output is correct
24 Correct 11 ms 23828 KB Output is correct
25 Correct 13 ms 23824 KB Output is correct
26 Correct 11 ms 23764 KB Output is correct
27 Correct 11 ms 23828 KB Output is correct
28 Correct 12 ms 23828 KB Output is correct
29 Correct 11 ms 23824 KB Output is correct
30 Correct 11 ms 23820 KB Output is correct
31 Correct 11 ms 23828 KB Output is correct
32 Correct 11 ms 23816 KB Output is correct
33 Correct 12 ms 23824 KB Output is correct
34 Correct 11 ms 23752 KB Output is correct
35 Correct 11 ms 23828 KB Output is correct
36 Correct 12 ms 23764 KB Output is correct
37 Correct 11 ms 23828 KB Output is correct
38 Correct 12 ms 23736 KB Output is correct
39 Correct 13 ms 23796 KB Output is correct
40 Correct 12 ms 23796 KB Output is correct
41 Correct 11 ms 23800 KB Output is correct
42 Correct 12 ms 23764 KB Output is correct
43 Correct 14 ms 23824 KB Output is correct
44 Correct 11 ms 23828 KB Output is correct
45 Correct 11 ms 23720 KB Output is correct
46 Correct 11 ms 23748 KB Output is correct
47 Correct 11 ms 23828 KB Output is correct
48 Correct 12 ms 23764 KB Output is correct
49 Correct 12 ms 23768 KB Output is correct
50 Correct 11 ms 23832 KB Output is correct
51 Correct 11 ms 23764 KB Output is correct
52 Correct 11 ms 23764 KB Output is correct
53 Correct 11 ms 23824 KB Output is correct
54 Correct 12 ms 23824 KB Output is correct
55 Correct 11 ms 23764 KB Output is correct
56 Correct 12 ms 23712 KB Output is correct
57 Correct 11 ms 23824 KB Output is correct
58 Correct 12 ms 23876 KB Output is correct
59 Correct 11 ms 23840 KB Output is correct
60 Correct 11 ms 23892 KB Output is correct
61 Correct 11 ms 23788 KB Output is correct
62 Correct 11 ms 23828 KB Output is correct
63 Correct 12 ms 23836 KB Output is correct
64 Correct 11 ms 23828 KB Output is correct
65 Correct 12 ms 23908 KB Output is correct
66 Correct 11 ms 23892 KB Output is correct
67 Correct 11 ms 23824 KB Output is correct
68 Correct 12 ms 23836 KB Output is correct
69 Correct 11 ms 23828 KB Output is correct
70 Correct 11 ms 23892 KB Output is correct
71 Correct 12 ms 23892 KB Output is correct
72 Correct 12 ms 23940 KB Output is correct
73 Correct 11 ms 23960 KB Output is correct
74 Correct 11 ms 23916 KB Output is correct
75 Correct 11 ms 23892 KB Output is correct
76 Correct 12 ms 23892 KB Output is correct
77 Correct 11 ms 23828 KB Output is correct
78 Correct 11 ms 23892 KB Output is correct
79 Correct 12 ms 23828 KB Output is correct
80 Correct 11 ms 23828 KB Output is correct
81 Correct 11 ms 23892 KB Output is correct
82 Correct 12 ms 23892 KB Output is correct
83 Correct 11 ms 23828 KB Output is correct
84 Correct 12 ms 23828 KB Output is correct
85 Correct 12 ms 23764 KB Output is correct
86 Correct 11 ms 23824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 11 ms 23740 KB Output is correct
3 Correct 12 ms 23836 KB Output is correct
4 Correct 12 ms 23824 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 12 ms 23712 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 11 ms 23792 KB Output is correct
9 Correct 11 ms 23724 KB Output is correct
10 Correct 12 ms 23812 KB Output is correct
11 Correct 11 ms 23816 KB Output is correct
12 Correct 11 ms 23740 KB Output is correct
13 Correct 11 ms 23808 KB Output is correct
14 Correct 11 ms 23764 KB Output is correct
15 Correct 11 ms 23824 KB Output is correct
16 Correct 11 ms 23820 KB Output is correct
17 Correct 11 ms 23776 KB Output is correct
18 Correct 12 ms 23736 KB Output is correct
19 Correct 12 ms 23824 KB Output is correct
20 Correct 12 ms 23824 KB Output is correct
21 Correct 12 ms 23776 KB Output is correct
22 Correct 11 ms 23764 KB Output is correct
23 Correct 11 ms 23828 KB Output is correct
24 Correct 11 ms 23828 KB Output is correct
25 Correct 13 ms 23824 KB Output is correct
26 Correct 11 ms 23764 KB Output is correct
27 Correct 11 ms 23828 KB Output is correct
28 Correct 12 ms 23828 KB Output is correct
29 Correct 11 ms 23824 KB Output is correct
30 Correct 11 ms 23820 KB Output is correct
31 Correct 11 ms 23828 KB Output is correct
32 Correct 11 ms 23816 KB Output is correct
33 Correct 12 ms 23824 KB Output is correct
34 Correct 11 ms 23752 KB Output is correct
35 Correct 11 ms 23828 KB Output is correct
36 Correct 12 ms 23764 KB Output is correct
37 Correct 11 ms 23828 KB Output is correct
38 Correct 12 ms 23736 KB Output is correct
39 Correct 13 ms 23796 KB Output is correct
40 Correct 12 ms 23796 KB Output is correct
41 Correct 11 ms 23800 KB Output is correct
42 Correct 12 ms 23764 KB Output is correct
43 Correct 14 ms 23824 KB Output is correct
44 Correct 11 ms 23828 KB Output is correct
45 Correct 11 ms 23720 KB Output is correct
46 Correct 11 ms 23748 KB Output is correct
47 Correct 11 ms 23828 KB Output is correct
48 Correct 12 ms 23764 KB Output is correct
49 Correct 12 ms 23768 KB Output is correct
50 Correct 11 ms 23832 KB Output is correct
51 Correct 11 ms 23764 KB Output is correct
52 Correct 11 ms 23764 KB Output is correct
53 Correct 11 ms 23824 KB Output is correct
54 Correct 12 ms 23824 KB Output is correct
55 Correct 11 ms 23764 KB Output is correct
56 Correct 12 ms 23712 KB Output is correct
57 Runtime error 63 ms 92908 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -