Submission #950595

# Submission time Handle Problem Language Result Execution time Memory
950595 2024-03-20T13:20:32 Z Vladth11 Homework (CEOI22_homework) C++14
53 / 100
102 ms 125644 KB
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")

using namespace std;
typedef long long ll;
typedef pair <int, int> pii;

const ll NMAX = 1000001;
const ll INF = (1LL << 58);
const ll nrbits = 20;
const ll MOD = 998244353;

vector <int> v[NMAX];
int pa[NMAX];
int op[NMAX];
pii sol[NMAX];
int nr;
int sz[NMAX];

pii combine(int a, int b, int o){
    if(sol[a].first > sol[a].second){
        return sol[a]; /// daca scorul e -1/0 continui
    }
    if(sol[b].first > sol[b].second){
        return sol[b]; /// daca scorul e -1/0 continui
    }


    if(o == 1){
        return {sol[a].first + sol[b].first, max(sz[a] + sol[b].second, sz[b] + sol[a].second)};
    }else{
        return {min(sol[a].first, sol[b].first), sol[a].second + sol[b].second - 1};
    }
}

void DFS(int node){
    if(!v[node].size()){
        sol[node] = {1, 1};
        sz[node] = 1;
        return;
    }
    DFS(v[node][0]);
    DFS(v[node][1]);
    sz[node] += sz[v[node][0]] + sz[v[node][1]];
    sol[node] = combine(v[node][0], v[node][1], op[node]);
}

signed main() {
#ifdef HOME
    ifstream cin(".in");
    ofstream cout(".out");
#endif // HOME
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int curent = 1, cnt = 1;
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == ','){
            v[curent].push_back(++cnt);
            pa[cnt] = curent;
            curent = cnt;
        }
        if(s[i] == '('){
            v[curent].push_back(++cnt);
            pa[cnt] = curent;
            curent = cnt;
        }
        if(s[i] == ')'){
            curent = pa[curent];
        }
        if(s[i] == '?') {
            nr++;
            curent = pa[curent];
        }
        if(s[i] == 'm'){
            if(s[i + 1] == 'a'){
                op[curent] = 1;
            }
            i += 2;
        }
    }
    DFS(1);
    cout << max(0, sol[1].second - sol[1].first + 1);
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:62:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int i = 0; i < s.size(); i++){
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 30812 KB Output is correct
2 Correct 8 ms 30808 KB Output is correct
3 Correct 7 ms 28760 KB Output is correct
4 Correct 9 ms 31068 KB Output is correct
5 Correct 7 ms 30812 KB Output is correct
6 Correct 7 ms 31012 KB Output is correct
7 Correct 7 ms 30808 KB Output is correct
8 Correct 7 ms 30808 KB Output is correct
9 Correct 7 ms 30812 KB Output is correct
10 Correct 7 ms 30808 KB Output is correct
11 Correct 7 ms 31020 KB Output is correct
12 Correct 7 ms 30812 KB Output is correct
13 Correct 7 ms 30812 KB Output is correct
14 Correct 8 ms 30812 KB Output is correct
15 Correct 7 ms 30812 KB Output is correct
16 Correct 7 ms 30896 KB Output is correct
17 Correct 8 ms 31020 KB Output is correct
18 Correct 7 ms 28764 KB Output is correct
19 Correct 7 ms 30812 KB Output is correct
20 Correct 7 ms 30812 KB Output is correct
21 Correct 8 ms 28888 KB Output is correct
22 Correct 7 ms 30808 KB Output is correct
23 Correct 7 ms 30808 KB Output is correct
24 Correct 7 ms 30812 KB Output is correct
25 Correct 8 ms 30808 KB Output is correct
26 Correct 7 ms 28764 KB Output is correct
27 Correct 7 ms 30812 KB Output is correct
28 Correct 7 ms 31016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 30812 KB Output is correct
2 Correct 8 ms 30808 KB Output is correct
3 Correct 7 ms 28760 KB Output is correct
4 Correct 9 ms 31068 KB Output is correct
5 Correct 7 ms 30812 KB Output is correct
6 Correct 7 ms 31012 KB Output is correct
7 Correct 7 ms 30808 KB Output is correct
8 Correct 7 ms 30808 KB Output is correct
9 Correct 7 ms 30812 KB Output is correct
10 Correct 7 ms 30808 KB Output is correct
11 Correct 7 ms 31020 KB Output is correct
12 Correct 7 ms 30812 KB Output is correct
13 Correct 7 ms 30812 KB Output is correct
14 Correct 8 ms 30812 KB Output is correct
15 Correct 7 ms 30812 KB Output is correct
16 Correct 7 ms 30896 KB Output is correct
17 Correct 8 ms 31020 KB Output is correct
18 Correct 7 ms 28764 KB Output is correct
19 Correct 7 ms 30812 KB Output is correct
20 Correct 7 ms 30812 KB Output is correct
21 Correct 8 ms 28888 KB Output is correct
22 Correct 7 ms 30808 KB Output is correct
23 Correct 7 ms 30808 KB Output is correct
24 Correct 7 ms 30812 KB Output is correct
25 Correct 8 ms 30808 KB Output is correct
26 Correct 7 ms 28764 KB Output is correct
27 Correct 7 ms 30812 KB Output is correct
28 Correct 7 ms 31016 KB Output is correct
29 Correct 7 ms 30812 KB Output is correct
30 Correct 7 ms 30912 KB Output is correct
31 Correct 7 ms 30808 KB Output is correct
32 Correct 7 ms 30812 KB Output is correct
33 Correct 7 ms 30812 KB Output is correct
34 Correct 7 ms 30812 KB Output is correct
35 Correct 7 ms 30812 KB Output is correct
36 Correct 7 ms 30812 KB Output is correct
37 Correct 7 ms 30812 KB Output is correct
38 Correct 8 ms 30816 KB Output is correct
39 Correct 7 ms 30816 KB Output is correct
40 Correct 7 ms 30808 KB Output is correct
41 Correct 7 ms 30812 KB Output is correct
42 Correct 7 ms 30812 KB Output is correct
43 Correct 7 ms 30812 KB Output is correct
44 Correct 7 ms 30812 KB Output is correct
45 Correct 7 ms 30812 KB Output is correct
46 Correct 7 ms 30812 KB Output is correct
47 Correct 7 ms 31020 KB Output is correct
48 Correct 7 ms 30812 KB Output is correct
49 Correct 7 ms 28764 KB Output is correct
50 Correct 7 ms 30812 KB Output is correct
51 Correct 8 ms 30812 KB Output is correct
52 Correct 7 ms 30964 KB Output is correct
53 Correct 7 ms 30808 KB Output is correct
54 Correct 7 ms 28764 KB Output is correct
55 Correct 7 ms 30812 KB Output is correct
56 Correct 7 ms 30812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 102 ms 125644 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 30812 KB Output is correct
2 Correct 8 ms 30808 KB Output is correct
3 Correct 7 ms 28760 KB Output is correct
4 Correct 9 ms 31068 KB Output is correct
5 Correct 7 ms 30812 KB Output is correct
6 Correct 7 ms 31012 KB Output is correct
7 Correct 7 ms 30808 KB Output is correct
8 Correct 7 ms 30808 KB Output is correct
9 Correct 7 ms 30812 KB Output is correct
10 Correct 7 ms 30808 KB Output is correct
11 Correct 7 ms 31020 KB Output is correct
12 Correct 7 ms 30812 KB Output is correct
13 Correct 7 ms 30812 KB Output is correct
14 Correct 8 ms 30812 KB Output is correct
15 Correct 7 ms 30812 KB Output is correct
16 Correct 7 ms 30896 KB Output is correct
17 Correct 8 ms 31020 KB Output is correct
18 Correct 7 ms 28764 KB Output is correct
19 Correct 7 ms 30812 KB Output is correct
20 Correct 7 ms 30812 KB Output is correct
21 Correct 8 ms 28888 KB Output is correct
22 Correct 7 ms 30808 KB Output is correct
23 Correct 7 ms 30808 KB Output is correct
24 Correct 7 ms 30812 KB Output is correct
25 Correct 8 ms 30808 KB Output is correct
26 Correct 7 ms 28764 KB Output is correct
27 Correct 7 ms 30812 KB Output is correct
28 Correct 7 ms 31016 KB Output is correct
29 Correct 7 ms 30812 KB Output is correct
30 Correct 7 ms 30912 KB Output is correct
31 Correct 7 ms 30808 KB Output is correct
32 Correct 7 ms 30812 KB Output is correct
33 Correct 7 ms 30812 KB Output is correct
34 Correct 7 ms 30812 KB Output is correct
35 Correct 7 ms 30812 KB Output is correct
36 Correct 7 ms 30812 KB Output is correct
37 Correct 7 ms 30812 KB Output is correct
38 Correct 8 ms 30816 KB Output is correct
39 Correct 7 ms 30816 KB Output is correct
40 Correct 7 ms 30808 KB Output is correct
41 Correct 7 ms 30812 KB Output is correct
42 Correct 7 ms 30812 KB Output is correct
43 Correct 7 ms 30812 KB Output is correct
44 Correct 7 ms 30812 KB Output is correct
45 Correct 7 ms 30812 KB Output is correct
46 Correct 7 ms 30812 KB Output is correct
47 Correct 7 ms 31020 KB Output is correct
48 Correct 7 ms 30812 KB Output is correct
49 Correct 7 ms 28764 KB Output is correct
50 Correct 7 ms 30812 KB Output is correct
51 Correct 8 ms 30812 KB Output is correct
52 Correct 7 ms 30964 KB Output is correct
53 Correct 7 ms 30808 KB Output is correct
54 Correct 7 ms 28764 KB Output is correct
55 Correct 7 ms 30812 KB Output is correct
56 Correct 7 ms 30812 KB Output is correct
57 Correct 7 ms 31068 KB Output is correct
58 Correct 8 ms 30912 KB Output is correct
59 Correct 7 ms 31068 KB Output is correct
60 Correct 7 ms 31080 KB Output is correct
61 Correct 7 ms 31068 KB Output is correct
62 Correct 7 ms 31068 KB Output is correct
63 Correct 7 ms 31068 KB Output is correct
64 Correct 7 ms 31056 KB Output is correct
65 Correct 7 ms 31016 KB Output is correct
66 Correct 7 ms 31032 KB Output is correct
67 Correct 8 ms 31064 KB Output is correct
68 Correct 7 ms 31068 KB Output is correct
69 Correct 7 ms 31028 KB Output is correct
70 Correct 7 ms 31064 KB Output is correct
71 Correct 7 ms 31068 KB Output is correct
72 Correct 8 ms 31016 KB Output is correct
73 Correct 7 ms 31068 KB Output is correct
74 Correct 7 ms 31068 KB Output is correct
75 Correct 7 ms 31068 KB Output is correct
76 Correct 7 ms 30928 KB Output is correct
77 Correct 7 ms 29020 KB Output is correct
78 Correct 8 ms 31068 KB Output is correct
79 Correct 7 ms 31068 KB Output is correct
80 Correct 8 ms 31068 KB Output is correct
81 Correct 7 ms 31068 KB Output is correct
82 Correct 7 ms 31320 KB Output is correct
83 Correct 7 ms 30812 KB Output is correct
84 Correct 7 ms 30908 KB Output is correct
85 Correct 7 ms 30812 KB Output is correct
86 Correct 8 ms 30808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 30812 KB Output is correct
2 Correct 8 ms 30808 KB Output is correct
3 Correct 7 ms 28760 KB Output is correct
4 Correct 9 ms 31068 KB Output is correct
5 Correct 7 ms 30812 KB Output is correct
6 Correct 7 ms 31012 KB Output is correct
7 Correct 7 ms 30808 KB Output is correct
8 Correct 7 ms 30808 KB Output is correct
9 Correct 7 ms 30812 KB Output is correct
10 Correct 7 ms 30808 KB Output is correct
11 Correct 7 ms 31020 KB Output is correct
12 Correct 7 ms 30812 KB Output is correct
13 Correct 7 ms 30812 KB Output is correct
14 Correct 8 ms 30812 KB Output is correct
15 Correct 7 ms 30812 KB Output is correct
16 Correct 7 ms 30896 KB Output is correct
17 Correct 8 ms 31020 KB Output is correct
18 Correct 7 ms 28764 KB Output is correct
19 Correct 7 ms 30812 KB Output is correct
20 Correct 7 ms 30812 KB Output is correct
21 Correct 8 ms 28888 KB Output is correct
22 Correct 7 ms 30808 KB Output is correct
23 Correct 7 ms 30808 KB Output is correct
24 Correct 7 ms 30812 KB Output is correct
25 Correct 8 ms 30808 KB Output is correct
26 Correct 7 ms 28764 KB Output is correct
27 Correct 7 ms 30812 KB Output is correct
28 Correct 7 ms 31016 KB Output is correct
29 Correct 7 ms 30812 KB Output is correct
30 Correct 7 ms 30912 KB Output is correct
31 Correct 7 ms 30808 KB Output is correct
32 Correct 7 ms 30812 KB Output is correct
33 Correct 7 ms 30812 KB Output is correct
34 Correct 7 ms 30812 KB Output is correct
35 Correct 7 ms 30812 KB Output is correct
36 Correct 7 ms 30812 KB Output is correct
37 Correct 7 ms 30812 KB Output is correct
38 Correct 8 ms 30816 KB Output is correct
39 Correct 7 ms 30816 KB Output is correct
40 Correct 7 ms 30808 KB Output is correct
41 Correct 7 ms 30812 KB Output is correct
42 Correct 7 ms 30812 KB Output is correct
43 Correct 7 ms 30812 KB Output is correct
44 Correct 7 ms 30812 KB Output is correct
45 Correct 7 ms 30812 KB Output is correct
46 Correct 7 ms 30812 KB Output is correct
47 Correct 7 ms 31020 KB Output is correct
48 Correct 7 ms 30812 KB Output is correct
49 Correct 7 ms 28764 KB Output is correct
50 Correct 7 ms 30812 KB Output is correct
51 Correct 8 ms 30812 KB Output is correct
52 Correct 7 ms 30964 KB Output is correct
53 Correct 7 ms 30808 KB Output is correct
54 Correct 7 ms 28764 KB Output is correct
55 Correct 7 ms 30812 KB Output is correct
56 Correct 7 ms 30812 KB Output is correct
57 Runtime error 102 ms 125644 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -