Submission #766591

# Submission time Handle Problem Language Result Execution time Memory
766591 2023-06-26T00:16:35 Z Pichon5 Homework (CEOI22_homework) C++17
100 / 100
309 ms 135772 KB
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <string>
#include <sstream>
#include <fstream>
#include <cmath>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <bits/stdc++.h>
#define lcm(a,b) (a/__gcd(a,b))*b
#define pb push_back
#define F first
#define S second
#define vi vector<int>
#define ll long long
#define int long long
#define fore for(int i = 0; i < n; i++)
using namespace std;
const int tam=2000005;
vi G[tam];
int color[tam];

int fmin(int nodo){
    if(G[nodo].size()==0)return 1;
    if(color[nodo]){
        int sum=0;
        for(auto it : G[nodo]){
            sum+=fmin(it);
        }
        return sum;
    }else{
        int mi=1e9;
        for(auto it : G[nodo]){
            mi=min(fmin(it),mi);
        }
        return mi;
    }
}

int fmax(int nodo){
    if(G[nodo].size()==0)return 1;
    if(color[nodo]==0){
        // cout<<"coloreado"<<endl;
        int sum=0;
        for(auto it : G[nodo]){
            sum+=fmax(it);
        }
        return sum;
    }else{
        int mi=1e9;
        for(auto it : G[nodo]){
            mi=min(fmax(it),mi);
        }
        return mi;
    }
}
signed main()
{
    string s;
    cin >> s;
    int n = s.size();
    stack<int>nodos;
    int nodo=1;
    int leaves=0;
    for(int i=0;i<n;i++){
        if(s[i]=='x'){
            nodos.push(nodo);
            color[nodo]=1;
            nodo++;
            continue;
        }
        if(s[i]=='n'){
            nodos.push(nodo);
            nodo++;
            continue;
        }
        if(s[i]=='?'){
            leaves++;
            int padre=nodos.top();
            G[padre].pb(nodo);
            nodo++;
        }
        if(s[i]==')'){
            int quito=nodos.top();
            nodos.pop();
            if(nodos.empty())continue;
            int padre=nodos.top();
            G[padre].pb(quito);
        }
    }
    //wanna print the graph
    for(int i=1;i<=n;i++){
        //cout<<i<<" : ";
        for(auto it : G[i]){
            // cout<<i<<" "<<it<<endl;
        }
    }
        // cout<<endl;
    int mi=fmin(1);
    // cout<<"mi  "<<mi<<endl;
    // for(int i=1;i<=n;i++){
    //     cout<<i<<" "<<color[i]<<endl;
    //     color[i]=!color[i];
    // }
    int ma=fmax(1);
    ma=leaves-ma+1;
    cout<<ma-mi+1<<endl;
    
    return 0;
}  

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:100:18: warning: unused variable 'it' [-Wunused-variable]
  100 |         for(auto it : G[i]){
      |                  ^~
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47188 KB Output is correct
2 Correct 23 ms 47172 KB Output is correct
3 Correct 22 ms 47188 KB Output is correct
4 Correct 23 ms 47276 KB Output is correct
5 Correct 23 ms 47156 KB Output is correct
6 Correct 23 ms 47276 KB Output is correct
7 Correct 23 ms 47200 KB Output is correct
8 Correct 25 ms 47276 KB Output is correct
9 Correct 24 ms 47260 KB Output is correct
10 Correct 24 ms 47216 KB Output is correct
11 Correct 25 ms 47152 KB Output is correct
12 Correct 24 ms 47268 KB Output is correct
13 Correct 24 ms 47252 KB Output is correct
14 Correct 24 ms 47188 KB Output is correct
15 Correct 26 ms 47308 KB Output is correct
16 Correct 24 ms 47240 KB Output is correct
17 Correct 25 ms 47272 KB Output is correct
18 Correct 25 ms 47244 KB Output is correct
19 Correct 24 ms 47276 KB Output is correct
20 Correct 25 ms 47208 KB Output is correct
21 Correct 24 ms 47188 KB Output is correct
22 Correct 26 ms 47268 KB Output is correct
23 Correct 24 ms 47188 KB Output is correct
24 Correct 24 ms 47196 KB Output is correct
25 Correct 25 ms 47224 KB Output is correct
26 Correct 25 ms 47260 KB Output is correct
27 Correct 25 ms 47228 KB Output is correct
28 Correct 24 ms 47192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47188 KB Output is correct
2 Correct 23 ms 47172 KB Output is correct
3 Correct 22 ms 47188 KB Output is correct
4 Correct 23 ms 47276 KB Output is correct
5 Correct 23 ms 47156 KB Output is correct
6 Correct 23 ms 47276 KB Output is correct
7 Correct 23 ms 47200 KB Output is correct
8 Correct 25 ms 47276 KB Output is correct
9 Correct 24 ms 47260 KB Output is correct
10 Correct 24 ms 47216 KB Output is correct
11 Correct 25 ms 47152 KB Output is correct
12 Correct 24 ms 47268 KB Output is correct
13 Correct 24 ms 47252 KB Output is correct
14 Correct 24 ms 47188 KB Output is correct
15 Correct 26 ms 47308 KB Output is correct
16 Correct 24 ms 47240 KB Output is correct
17 Correct 25 ms 47272 KB Output is correct
18 Correct 25 ms 47244 KB Output is correct
19 Correct 24 ms 47276 KB Output is correct
20 Correct 25 ms 47208 KB Output is correct
21 Correct 24 ms 47188 KB Output is correct
22 Correct 26 ms 47268 KB Output is correct
23 Correct 24 ms 47188 KB Output is correct
24 Correct 24 ms 47196 KB Output is correct
25 Correct 25 ms 47224 KB Output is correct
26 Correct 25 ms 47260 KB Output is correct
27 Correct 25 ms 47228 KB Output is correct
28 Correct 24 ms 47192 KB Output is correct
29 Correct 24 ms 47276 KB Output is correct
30 Correct 23 ms 47188 KB Output is correct
31 Correct 24 ms 47200 KB Output is correct
32 Correct 24 ms 47180 KB Output is correct
33 Correct 25 ms 47276 KB Output is correct
34 Correct 25 ms 47280 KB Output is correct
35 Correct 24 ms 47244 KB Output is correct
36 Correct 24 ms 47176 KB Output is correct
37 Correct 24 ms 47152 KB Output is correct
38 Correct 25 ms 47248 KB Output is correct
39 Correct 24 ms 47244 KB Output is correct
40 Correct 24 ms 47280 KB Output is correct
41 Correct 25 ms 47188 KB Output is correct
42 Correct 24 ms 47188 KB Output is correct
43 Correct 27 ms 47252 KB Output is correct
44 Correct 24 ms 47188 KB Output is correct
45 Correct 25 ms 47332 KB Output is correct
46 Correct 26 ms 47296 KB Output is correct
47 Correct 23 ms 47208 KB Output is correct
48 Correct 24 ms 47244 KB Output is correct
49 Correct 24 ms 47208 KB Output is correct
50 Correct 23 ms 47188 KB Output is correct
51 Correct 23 ms 47244 KB Output is correct
52 Correct 23 ms 47236 KB Output is correct
53 Correct 23 ms 47232 KB Output is correct
54 Correct 23 ms 47260 KB Output is correct
55 Correct 26 ms 47188 KB Output is correct
56 Correct 23 ms 47188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 289 ms 123908 KB Output is correct
2 Correct 289 ms 135592 KB Output is correct
3 Correct 309 ms 135772 KB Output is correct
4 Correct 305 ms 135652 KB Output is correct
5 Correct 292 ms 135676 KB Output is correct
6 Correct 287 ms 135688 KB Output is correct
7 Correct 288 ms 135580 KB Output is correct
8 Correct 294 ms 135768 KB Output is correct
9 Correct 289 ms 135668 KB Output is correct
10 Correct 299 ms 135664 KB Output is correct
11 Correct 290 ms 135700 KB Output is correct
12 Correct 287 ms 135580 KB Output is correct
13 Correct 23 ms 47188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47188 KB Output is correct
2 Correct 23 ms 47172 KB Output is correct
3 Correct 22 ms 47188 KB Output is correct
4 Correct 23 ms 47276 KB Output is correct
5 Correct 23 ms 47156 KB Output is correct
6 Correct 23 ms 47276 KB Output is correct
7 Correct 23 ms 47200 KB Output is correct
8 Correct 25 ms 47276 KB Output is correct
9 Correct 24 ms 47260 KB Output is correct
10 Correct 24 ms 47216 KB Output is correct
11 Correct 25 ms 47152 KB Output is correct
12 Correct 24 ms 47268 KB Output is correct
13 Correct 24 ms 47252 KB Output is correct
14 Correct 24 ms 47188 KB Output is correct
15 Correct 26 ms 47308 KB Output is correct
16 Correct 24 ms 47240 KB Output is correct
17 Correct 25 ms 47272 KB Output is correct
18 Correct 25 ms 47244 KB Output is correct
19 Correct 24 ms 47276 KB Output is correct
20 Correct 25 ms 47208 KB Output is correct
21 Correct 24 ms 47188 KB Output is correct
22 Correct 26 ms 47268 KB Output is correct
23 Correct 24 ms 47188 KB Output is correct
24 Correct 24 ms 47196 KB Output is correct
25 Correct 25 ms 47224 KB Output is correct
26 Correct 25 ms 47260 KB Output is correct
27 Correct 25 ms 47228 KB Output is correct
28 Correct 24 ms 47192 KB Output is correct
29 Correct 24 ms 47276 KB Output is correct
30 Correct 23 ms 47188 KB Output is correct
31 Correct 24 ms 47200 KB Output is correct
32 Correct 24 ms 47180 KB Output is correct
33 Correct 25 ms 47276 KB Output is correct
34 Correct 25 ms 47280 KB Output is correct
35 Correct 24 ms 47244 KB Output is correct
36 Correct 24 ms 47176 KB Output is correct
37 Correct 24 ms 47152 KB Output is correct
38 Correct 25 ms 47248 KB Output is correct
39 Correct 24 ms 47244 KB Output is correct
40 Correct 24 ms 47280 KB Output is correct
41 Correct 25 ms 47188 KB Output is correct
42 Correct 24 ms 47188 KB Output is correct
43 Correct 27 ms 47252 KB Output is correct
44 Correct 24 ms 47188 KB Output is correct
45 Correct 25 ms 47332 KB Output is correct
46 Correct 26 ms 47296 KB Output is correct
47 Correct 23 ms 47208 KB Output is correct
48 Correct 24 ms 47244 KB Output is correct
49 Correct 24 ms 47208 KB Output is correct
50 Correct 23 ms 47188 KB Output is correct
51 Correct 23 ms 47244 KB Output is correct
52 Correct 23 ms 47236 KB Output is correct
53 Correct 23 ms 47232 KB Output is correct
54 Correct 23 ms 47260 KB Output is correct
55 Correct 26 ms 47188 KB Output is correct
56 Correct 23 ms 47188 KB Output is correct
57 Correct 23 ms 47316 KB Output is correct
58 Correct 23 ms 47336 KB Output is correct
59 Correct 23 ms 47244 KB Output is correct
60 Correct 23 ms 47280 KB Output is correct
61 Correct 23 ms 47308 KB Output is correct
62 Correct 24 ms 47328 KB Output is correct
63 Correct 24 ms 47260 KB Output is correct
64 Correct 22 ms 47316 KB Output is correct
65 Correct 23 ms 47316 KB Output is correct
66 Correct 23 ms 47280 KB Output is correct
67 Correct 24 ms 47212 KB Output is correct
68 Correct 26 ms 47276 KB Output is correct
69 Correct 24 ms 47268 KB Output is correct
70 Correct 24 ms 47284 KB Output is correct
71 Correct 25 ms 47320 KB Output is correct
72 Correct 24 ms 47316 KB Output is correct
73 Correct 24 ms 47348 KB Output is correct
74 Correct 26 ms 47328 KB Output is correct
75 Correct 23 ms 47268 KB Output is correct
76 Correct 23 ms 47328 KB Output is correct
77 Correct 25 ms 47280 KB Output is correct
78 Correct 24 ms 47236 KB Output is correct
79 Correct 26 ms 47316 KB Output is correct
80 Correct 24 ms 47316 KB Output is correct
81 Correct 24 ms 47280 KB Output is correct
82 Correct 24 ms 47232 KB Output is correct
83 Correct 23 ms 47220 KB Output is correct
84 Correct 24 ms 47188 KB Output is correct
85 Correct 25 ms 47188 KB Output is correct
86 Correct 23 ms 47188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47188 KB Output is correct
2 Correct 23 ms 47172 KB Output is correct
3 Correct 22 ms 47188 KB Output is correct
4 Correct 23 ms 47276 KB Output is correct
5 Correct 23 ms 47156 KB Output is correct
6 Correct 23 ms 47276 KB Output is correct
7 Correct 23 ms 47200 KB Output is correct
8 Correct 25 ms 47276 KB Output is correct
9 Correct 24 ms 47260 KB Output is correct
10 Correct 24 ms 47216 KB Output is correct
11 Correct 25 ms 47152 KB Output is correct
12 Correct 24 ms 47268 KB Output is correct
13 Correct 24 ms 47252 KB Output is correct
14 Correct 24 ms 47188 KB Output is correct
15 Correct 26 ms 47308 KB Output is correct
16 Correct 24 ms 47240 KB Output is correct
17 Correct 25 ms 47272 KB Output is correct
18 Correct 25 ms 47244 KB Output is correct
19 Correct 24 ms 47276 KB Output is correct
20 Correct 25 ms 47208 KB Output is correct
21 Correct 24 ms 47188 KB Output is correct
22 Correct 26 ms 47268 KB Output is correct
23 Correct 24 ms 47188 KB Output is correct
24 Correct 24 ms 47196 KB Output is correct
25 Correct 25 ms 47224 KB Output is correct
26 Correct 25 ms 47260 KB Output is correct
27 Correct 25 ms 47228 KB Output is correct
28 Correct 24 ms 47192 KB Output is correct
29 Correct 24 ms 47276 KB Output is correct
30 Correct 23 ms 47188 KB Output is correct
31 Correct 24 ms 47200 KB Output is correct
32 Correct 24 ms 47180 KB Output is correct
33 Correct 25 ms 47276 KB Output is correct
34 Correct 25 ms 47280 KB Output is correct
35 Correct 24 ms 47244 KB Output is correct
36 Correct 24 ms 47176 KB Output is correct
37 Correct 24 ms 47152 KB Output is correct
38 Correct 25 ms 47248 KB Output is correct
39 Correct 24 ms 47244 KB Output is correct
40 Correct 24 ms 47280 KB Output is correct
41 Correct 25 ms 47188 KB Output is correct
42 Correct 24 ms 47188 KB Output is correct
43 Correct 27 ms 47252 KB Output is correct
44 Correct 24 ms 47188 KB Output is correct
45 Correct 25 ms 47332 KB Output is correct
46 Correct 26 ms 47296 KB Output is correct
47 Correct 23 ms 47208 KB Output is correct
48 Correct 24 ms 47244 KB Output is correct
49 Correct 24 ms 47208 KB Output is correct
50 Correct 23 ms 47188 KB Output is correct
51 Correct 23 ms 47244 KB Output is correct
52 Correct 23 ms 47236 KB Output is correct
53 Correct 23 ms 47232 KB Output is correct
54 Correct 23 ms 47260 KB Output is correct
55 Correct 26 ms 47188 KB Output is correct
56 Correct 23 ms 47188 KB Output is correct
57 Correct 289 ms 123908 KB Output is correct
58 Correct 289 ms 135592 KB Output is correct
59 Correct 309 ms 135772 KB Output is correct
60 Correct 305 ms 135652 KB Output is correct
61 Correct 292 ms 135676 KB Output is correct
62 Correct 287 ms 135688 KB Output is correct
63 Correct 288 ms 135580 KB Output is correct
64 Correct 294 ms 135768 KB Output is correct
65 Correct 289 ms 135668 KB Output is correct
66 Correct 299 ms 135664 KB Output is correct
67 Correct 290 ms 135700 KB Output is correct
68 Correct 287 ms 135580 KB Output is correct
69 Correct 23 ms 47188 KB Output is correct
70 Correct 23 ms 47316 KB Output is correct
71 Correct 23 ms 47336 KB Output is correct
72 Correct 23 ms 47244 KB Output is correct
73 Correct 23 ms 47280 KB Output is correct
74 Correct 23 ms 47308 KB Output is correct
75 Correct 24 ms 47328 KB Output is correct
76 Correct 24 ms 47260 KB Output is correct
77 Correct 22 ms 47316 KB Output is correct
78 Correct 23 ms 47316 KB Output is correct
79 Correct 23 ms 47280 KB Output is correct
80 Correct 24 ms 47212 KB Output is correct
81 Correct 26 ms 47276 KB Output is correct
82 Correct 24 ms 47268 KB Output is correct
83 Correct 24 ms 47284 KB Output is correct
84 Correct 25 ms 47320 KB Output is correct
85 Correct 24 ms 47316 KB Output is correct
86 Correct 24 ms 47348 KB Output is correct
87 Correct 26 ms 47328 KB Output is correct
88 Correct 23 ms 47268 KB Output is correct
89 Correct 23 ms 47328 KB Output is correct
90 Correct 25 ms 47280 KB Output is correct
91 Correct 24 ms 47236 KB Output is correct
92 Correct 26 ms 47316 KB Output is correct
93 Correct 24 ms 47316 KB Output is correct
94 Correct 24 ms 47280 KB Output is correct
95 Correct 24 ms 47232 KB Output is correct
96 Correct 23 ms 47220 KB Output is correct
97 Correct 24 ms 47188 KB Output is correct
98 Correct 25 ms 47188 KB Output is correct
99 Correct 23 ms 47188 KB Output is correct
100 Correct 274 ms 107912 KB Output is correct
101 Correct 285 ms 108068 KB Output is correct
102 Correct 261 ms 107920 KB Output is correct
103 Correct 266 ms 107936 KB Output is correct
104 Correct 258 ms 107792 KB Output is correct
105 Correct 285 ms 118440 KB Output is correct
106 Correct 290 ms 118596 KB Output is correct
107 Correct 273 ms 118408 KB Output is correct
108 Correct 271 ms 118476 KB Output is correct
109 Correct 276 ms 118444 KB Output is correct
110 Correct 282 ms 107820 KB Output is correct
111 Correct 288 ms 108152 KB Output is correct
112 Correct 272 ms 107808 KB Output is correct
113 Correct 272 ms 107788 KB Output is correct
114 Correct 271 ms 107812 KB Output is correct
115 Correct 305 ms 135592 KB Output is correct
116 Correct 301 ms 135696 KB Output is correct
117 Correct 295 ms 135660 KB Output is correct
118 Correct 291 ms 135696 KB Output is correct
119 Correct 288 ms 135588 KB Output is correct
120 Correct 280 ms 92256 KB Output is correct
121 Correct 276 ms 107916 KB Output is correct
122 Correct 282 ms 107824 KB Output is correct
123 Correct 283 ms 107912 KB Output is correct
124 Correct 263 ms 127636 KB Output is correct
125 Correct 265 ms 119852 KB Output is correct
126 Correct 268 ms 127560 KB Output is correct
127 Correct 262 ms 119860 KB Output is correct
128 Correct 158 ms 79056 KB Output is correct
129 Correct 172 ms 79068 KB Output is correct
130 Correct 138 ms 78992 KB Output is correct
131 Correct 25 ms 47188 KB Output is correct