답안 #696967

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
696967 2023-02-07T18:36:30 Z Deepesson Homework (CEOI22_homework) C++17
100 / 100
342 ms 247016 KB
#include <bits/stdc++.h>
#define MAX 5005005

typedef std::pair<int,int> pii;
///Garantido que con=2
std::vector<int> con[MAX];
int types[MAX];
enum tipos {MINIMO=1,MAXIMO};
int N;
int rodada=42;
///0 -> Menor que objetivo
///1 -> Maior que objetivo
int turno[MAX][2];
int tab[MAX][2];
int dp(int pos,int modo){
    if(!types[pos]){///Folha
        return 1;
    }
    if(turno[pos][modo]==rodada)return tab[pos][modo];
    turno[pos][modo]=rodada;
    int ans=1e9;
    ///Procurando valores menores que objetivo
    if(modo==0){
        if(types[pos]==MINIMO){
            ans=std::min(ans,dp(con[pos][0],modo));
            ans=std::min(ans,dp(con[pos][1],modo));
        }else {
            ans=dp(con[pos][0],modo)+dp(con[pos][1],modo);
        }
    ///Procurando valores maiores que objetivo
    }else {
        if(types[pos]==MINIMO){
            ans=dp(con[pos][0],modo)+dp(con[pos][1],modo);
        }else {
            ans=std::min(ans,dp(con[pos][0],modo));
            ans=std::min(ans,dp(con[pos][1],modo));
        }
    }
    return tab[pos][modo]=ans;
}
///Left -> valores menores que obj, Right -> valores maiores que obj
int left,right,objetivo;
int marcas[MAX];
void dfs(int pos){
    if(!types[pos]){///Eh folha
        int inicio=left+1;
        int fim = (N-right);
        marcas[inicio]++;
        marcas[fim+1]--;
        return;
    }
    if(types[pos]==MINIMO){///Temos que ter um valor = X e outro maior que X
        int esq = dp(con[pos][0],1),dir = dp(con[pos][1],1);
        right+=esq;
        dfs(con[pos][1]);
        right+=-esq+dir;
        dfs(con[pos][0]);
        right+=-dir;
    }else if(types[pos]==MAXIMO){///Temos que ter um valor = X e outro menor que X
        int esq = dp(con[pos][0],0),dir = dp(con[pos][1],0);
        left+=esq;
        dfs(con[pos][1]);
        left+=-esq+dir;
        dfs(con[pos][0]);
        left+=-dir;
    }
    return;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    std::string s;
    std::cin>>s;
    for(auto&x:s)if(x=='?')++N;
    ///Destrinchar
    std::vector<int> stack;
    int cur=0;
    for(int i=0;i<s.size();++i){
        if(s[i]==',')continue;
        if(s[i]==')'){
            stack.pop_back();
            continue;
        }
        if(s[i]=='?'){
            con[stack.back()].push_back(cur);
            ++cur;
            continue;
        }
        if(s[i]=='m'){
            if(stack.size())
            con[stack.back()].push_back(cur);
            int tipo=MINIMO;
            if(s[i+1]=='a')tipo=MAXIMO;
            i+=3;
            stack.push_back(cur);
            types[cur]=tipo;
            ++cur;
        }else std::cout<<s[i];
    }
    dfs(0);
    int count=0,curs=0;
    for(int i=1;i<=N;++i){
        curs+=marcas[i];
        if(curs)++count;
    }
    std::cout<<count<<"\n";
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:80:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     for(int i=0;i<s.size();++i){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 117812 KB Output is correct
2 Correct 54 ms 117856 KB Output is correct
3 Correct 55 ms 117860 KB Output is correct
4 Correct 53 ms 117852 KB Output is correct
5 Correct 61 ms 117840 KB Output is correct
6 Correct 54 ms 117776 KB Output is correct
7 Correct 55 ms 117832 KB Output is correct
8 Correct 53 ms 117848 KB Output is correct
9 Correct 53 ms 117772 KB Output is correct
10 Correct 54 ms 117868 KB Output is correct
11 Correct 55 ms 117808 KB Output is correct
12 Correct 54 ms 117864 KB Output is correct
13 Correct 59 ms 117756 KB Output is correct
14 Correct 54 ms 117872 KB Output is correct
15 Correct 53 ms 117800 KB Output is correct
16 Correct 55 ms 117848 KB Output is correct
17 Correct 54 ms 117768 KB Output is correct
18 Correct 61 ms 117836 KB Output is correct
19 Correct 57 ms 117844 KB Output is correct
20 Correct 63 ms 117816 KB Output is correct
21 Correct 53 ms 117772 KB Output is correct
22 Correct 53 ms 117748 KB Output is correct
23 Correct 55 ms 117764 KB Output is correct
24 Correct 57 ms 117756 KB Output is correct
25 Correct 57 ms 117860 KB Output is correct
26 Correct 54 ms 117828 KB Output is correct
27 Correct 56 ms 117752 KB Output is correct
28 Correct 74 ms 117808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 117812 KB Output is correct
2 Correct 54 ms 117856 KB Output is correct
3 Correct 55 ms 117860 KB Output is correct
4 Correct 53 ms 117852 KB Output is correct
5 Correct 61 ms 117840 KB Output is correct
6 Correct 54 ms 117776 KB Output is correct
7 Correct 55 ms 117832 KB Output is correct
8 Correct 53 ms 117848 KB Output is correct
9 Correct 53 ms 117772 KB Output is correct
10 Correct 54 ms 117868 KB Output is correct
11 Correct 55 ms 117808 KB Output is correct
12 Correct 54 ms 117864 KB Output is correct
13 Correct 59 ms 117756 KB Output is correct
14 Correct 54 ms 117872 KB Output is correct
15 Correct 53 ms 117800 KB Output is correct
16 Correct 55 ms 117848 KB Output is correct
17 Correct 54 ms 117768 KB Output is correct
18 Correct 61 ms 117836 KB Output is correct
19 Correct 57 ms 117844 KB Output is correct
20 Correct 63 ms 117816 KB Output is correct
21 Correct 53 ms 117772 KB Output is correct
22 Correct 53 ms 117748 KB Output is correct
23 Correct 55 ms 117764 KB Output is correct
24 Correct 57 ms 117756 KB Output is correct
25 Correct 57 ms 117860 KB Output is correct
26 Correct 54 ms 117828 KB Output is correct
27 Correct 56 ms 117752 KB Output is correct
28 Correct 74 ms 117808 KB Output is correct
29 Correct 56 ms 117840 KB Output is correct
30 Correct 55 ms 117856 KB Output is correct
31 Correct 55 ms 117860 KB Output is correct
32 Correct 57 ms 117740 KB Output is correct
33 Correct 57 ms 117756 KB Output is correct
34 Correct 63 ms 117800 KB Output is correct
35 Correct 62 ms 117808 KB Output is correct
36 Correct 55 ms 117816 KB Output is correct
37 Correct 56 ms 117784 KB Output is correct
38 Correct 55 ms 117840 KB Output is correct
39 Correct 59 ms 117836 KB Output is correct
40 Correct 65 ms 117840 KB Output is correct
41 Correct 57 ms 117812 KB Output is correct
42 Correct 55 ms 117836 KB Output is correct
43 Correct 54 ms 117828 KB Output is correct
44 Correct 55 ms 117864 KB Output is correct
45 Correct 55 ms 117868 KB Output is correct
46 Correct 57 ms 117908 KB Output is correct
47 Correct 57 ms 117792 KB Output is correct
48 Correct 58 ms 117864 KB Output is correct
49 Correct 56 ms 117776 KB Output is correct
50 Correct 55 ms 117860 KB Output is correct
51 Correct 69 ms 117836 KB Output is correct
52 Correct 59 ms 117868 KB Output is correct
53 Correct 58 ms 117880 KB Output is correct
54 Correct 58 ms 117768 KB Output is correct
55 Correct 58 ms 117836 KB Output is correct
56 Correct 55 ms 117748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 274 ms 236224 KB Output is correct
2 Correct 274 ms 236628 KB Output is correct
3 Correct 314 ms 240340 KB Output is correct
4 Correct 328 ms 240456 KB Output is correct
5 Correct 293 ms 240428 KB Output is correct
6 Correct 335 ms 240348 KB Output is correct
7 Correct 311 ms 240348 KB Output is correct
8 Correct 298 ms 240452 KB Output is correct
9 Correct 298 ms 240448 KB Output is correct
10 Correct 322 ms 240392 KB Output is correct
11 Correct 296 ms 240536 KB Output is correct
12 Correct 293 ms 240444 KB Output is correct
13 Correct 59 ms 117868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 117812 KB Output is correct
2 Correct 54 ms 117856 KB Output is correct
3 Correct 55 ms 117860 KB Output is correct
4 Correct 53 ms 117852 KB Output is correct
5 Correct 61 ms 117840 KB Output is correct
6 Correct 54 ms 117776 KB Output is correct
7 Correct 55 ms 117832 KB Output is correct
8 Correct 53 ms 117848 KB Output is correct
9 Correct 53 ms 117772 KB Output is correct
10 Correct 54 ms 117868 KB Output is correct
11 Correct 55 ms 117808 KB Output is correct
12 Correct 54 ms 117864 KB Output is correct
13 Correct 59 ms 117756 KB Output is correct
14 Correct 54 ms 117872 KB Output is correct
15 Correct 53 ms 117800 KB Output is correct
16 Correct 55 ms 117848 KB Output is correct
17 Correct 54 ms 117768 KB Output is correct
18 Correct 61 ms 117836 KB Output is correct
19 Correct 57 ms 117844 KB Output is correct
20 Correct 63 ms 117816 KB Output is correct
21 Correct 53 ms 117772 KB Output is correct
22 Correct 53 ms 117748 KB Output is correct
23 Correct 55 ms 117764 KB Output is correct
24 Correct 57 ms 117756 KB Output is correct
25 Correct 57 ms 117860 KB Output is correct
26 Correct 54 ms 117828 KB Output is correct
27 Correct 56 ms 117752 KB Output is correct
28 Correct 74 ms 117808 KB Output is correct
29 Correct 56 ms 117840 KB Output is correct
30 Correct 55 ms 117856 KB Output is correct
31 Correct 55 ms 117860 KB Output is correct
32 Correct 57 ms 117740 KB Output is correct
33 Correct 57 ms 117756 KB Output is correct
34 Correct 63 ms 117800 KB Output is correct
35 Correct 62 ms 117808 KB Output is correct
36 Correct 55 ms 117816 KB Output is correct
37 Correct 56 ms 117784 KB Output is correct
38 Correct 55 ms 117840 KB Output is correct
39 Correct 59 ms 117836 KB Output is correct
40 Correct 65 ms 117840 KB Output is correct
41 Correct 57 ms 117812 KB Output is correct
42 Correct 55 ms 117836 KB Output is correct
43 Correct 54 ms 117828 KB Output is correct
44 Correct 55 ms 117864 KB Output is correct
45 Correct 55 ms 117868 KB Output is correct
46 Correct 57 ms 117908 KB Output is correct
47 Correct 57 ms 117792 KB Output is correct
48 Correct 58 ms 117864 KB Output is correct
49 Correct 56 ms 117776 KB Output is correct
50 Correct 55 ms 117860 KB Output is correct
51 Correct 69 ms 117836 KB Output is correct
52 Correct 59 ms 117868 KB Output is correct
53 Correct 58 ms 117880 KB Output is correct
54 Correct 58 ms 117768 KB Output is correct
55 Correct 58 ms 117836 KB Output is correct
56 Correct 55 ms 117748 KB Output is correct
57 Correct 68 ms 117980 KB Output is correct
58 Correct 57 ms 117948 KB Output is correct
59 Correct 54 ms 117944 KB Output is correct
60 Correct 55 ms 117888 KB Output is correct
61 Correct 58 ms 117832 KB Output is correct
62 Correct 54 ms 117952 KB Output is correct
63 Correct 66 ms 117964 KB Output is correct
64 Correct 62 ms 117972 KB Output is correct
65 Correct 54 ms 117952 KB Output is correct
66 Correct 64 ms 117860 KB Output is correct
67 Correct 56 ms 117952 KB Output is correct
68 Correct 55 ms 117944 KB Output is correct
69 Correct 59 ms 117836 KB Output is correct
70 Correct 57 ms 117896 KB Output is correct
71 Correct 55 ms 117884 KB Output is correct
72 Correct 55 ms 117936 KB Output is correct
73 Correct 56 ms 117988 KB Output is correct
74 Correct 55 ms 117912 KB Output is correct
75 Correct 55 ms 117884 KB Output is correct
76 Correct 54 ms 117924 KB Output is correct
77 Correct 55 ms 117868 KB Output is correct
78 Correct 57 ms 117872 KB Output is correct
79 Correct 64 ms 117952 KB Output is correct
80 Correct 55 ms 117948 KB Output is correct
81 Correct 55 ms 117964 KB Output is correct
82 Correct 60 ms 117856 KB Output is correct
83 Correct 61 ms 117976 KB Output is correct
84 Correct 57 ms 117860 KB Output is correct
85 Correct 54 ms 117912 KB Output is correct
86 Correct 54 ms 117836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 117812 KB Output is correct
2 Correct 54 ms 117856 KB Output is correct
3 Correct 55 ms 117860 KB Output is correct
4 Correct 53 ms 117852 KB Output is correct
5 Correct 61 ms 117840 KB Output is correct
6 Correct 54 ms 117776 KB Output is correct
7 Correct 55 ms 117832 KB Output is correct
8 Correct 53 ms 117848 KB Output is correct
9 Correct 53 ms 117772 KB Output is correct
10 Correct 54 ms 117868 KB Output is correct
11 Correct 55 ms 117808 KB Output is correct
12 Correct 54 ms 117864 KB Output is correct
13 Correct 59 ms 117756 KB Output is correct
14 Correct 54 ms 117872 KB Output is correct
15 Correct 53 ms 117800 KB Output is correct
16 Correct 55 ms 117848 KB Output is correct
17 Correct 54 ms 117768 KB Output is correct
18 Correct 61 ms 117836 KB Output is correct
19 Correct 57 ms 117844 KB Output is correct
20 Correct 63 ms 117816 KB Output is correct
21 Correct 53 ms 117772 KB Output is correct
22 Correct 53 ms 117748 KB Output is correct
23 Correct 55 ms 117764 KB Output is correct
24 Correct 57 ms 117756 KB Output is correct
25 Correct 57 ms 117860 KB Output is correct
26 Correct 54 ms 117828 KB Output is correct
27 Correct 56 ms 117752 KB Output is correct
28 Correct 74 ms 117808 KB Output is correct
29 Correct 56 ms 117840 KB Output is correct
30 Correct 55 ms 117856 KB Output is correct
31 Correct 55 ms 117860 KB Output is correct
32 Correct 57 ms 117740 KB Output is correct
33 Correct 57 ms 117756 KB Output is correct
34 Correct 63 ms 117800 KB Output is correct
35 Correct 62 ms 117808 KB Output is correct
36 Correct 55 ms 117816 KB Output is correct
37 Correct 56 ms 117784 KB Output is correct
38 Correct 55 ms 117840 KB Output is correct
39 Correct 59 ms 117836 KB Output is correct
40 Correct 65 ms 117840 KB Output is correct
41 Correct 57 ms 117812 KB Output is correct
42 Correct 55 ms 117836 KB Output is correct
43 Correct 54 ms 117828 KB Output is correct
44 Correct 55 ms 117864 KB Output is correct
45 Correct 55 ms 117868 KB Output is correct
46 Correct 57 ms 117908 KB Output is correct
47 Correct 57 ms 117792 KB Output is correct
48 Correct 58 ms 117864 KB Output is correct
49 Correct 56 ms 117776 KB Output is correct
50 Correct 55 ms 117860 KB Output is correct
51 Correct 69 ms 117836 KB Output is correct
52 Correct 59 ms 117868 KB Output is correct
53 Correct 58 ms 117880 KB Output is correct
54 Correct 58 ms 117768 KB Output is correct
55 Correct 58 ms 117836 KB Output is correct
56 Correct 55 ms 117748 KB Output is correct
57 Correct 274 ms 236224 KB Output is correct
58 Correct 274 ms 236628 KB Output is correct
59 Correct 314 ms 240340 KB Output is correct
60 Correct 328 ms 240456 KB Output is correct
61 Correct 293 ms 240428 KB Output is correct
62 Correct 335 ms 240348 KB Output is correct
63 Correct 311 ms 240348 KB Output is correct
64 Correct 298 ms 240452 KB Output is correct
65 Correct 298 ms 240448 KB Output is correct
66 Correct 322 ms 240392 KB Output is correct
67 Correct 296 ms 240536 KB Output is correct
68 Correct 293 ms 240444 KB Output is correct
69 Correct 59 ms 117868 KB Output is correct
70 Correct 68 ms 117980 KB Output is correct
71 Correct 57 ms 117948 KB Output is correct
72 Correct 54 ms 117944 KB Output is correct
73 Correct 55 ms 117888 KB Output is correct
74 Correct 58 ms 117832 KB Output is correct
75 Correct 54 ms 117952 KB Output is correct
76 Correct 66 ms 117964 KB Output is correct
77 Correct 62 ms 117972 KB Output is correct
78 Correct 54 ms 117952 KB Output is correct
79 Correct 64 ms 117860 KB Output is correct
80 Correct 56 ms 117952 KB Output is correct
81 Correct 55 ms 117944 KB Output is correct
82 Correct 59 ms 117836 KB Output is correct
83 Correct 57 ms 117896 KB Output is correct
84 Correct 55 ms 117884 KB Output is correct
85 Correct 55 ms 117936 KB Output is correct
86 Correct 56 ms 117988 KB Output is correct
87 Correct 55 ms 117912 KB Output is correct
88 Correct 55 ms 117884 KB Output is correct
89 Correct 54 ms 117924 KB Output is correct
90 Correct 55 ms 117868 KB Output is correct
91 Correct 57 ms 117872 KB Output is correct
92 Correct 64 ms 117952 KB Output is correct
93 Correct 55 ms 117948 KB Output is correct
94 Correct 55 ms 117964 KB Output is correct
95 Correct 60 ms 117856 KB Output is correct
96 Correct 61 ms 117976 KB Output is correct
97 Correct 57 ms 117860 KB Output is correct
98 Correct 54 ms 117912 KB Output is correct
99 Correct 54 ms 117836 KB Output is correct
100 Correct 285 ms 202012 KB Output is correct
101 Correct 305 ms 202064 KB Output is correct
102 Correct 278 ms 201992 KB Output is correct
103 Correct 287 ms 202080 KB Output is correct
104 Correct 273 ms 202124 KB Output is correct
105 Correct 310 ms 221304 KB Output is correct
106 Correct 311 ms 221208 KB Output is correct
107 Correct 288 ms 222164 KB Output is correct
108 Correct 290 ms 222272 KB Output is correct
109 Correct 294 ms 220428 KB Output is correct
110 Correct 301 ms 202064 KB Output is correct
111 Correct 290 ms 202044 KB Output is correct
112 Correct 302 ms 202036 KB Output is correct
113 Correct 283 ms 202052 KB Output is correct
114 Correct 319 ms 202004 KB Output is correct
115 Correct 338 ms 247016 KB Output is correct
116 Correct 342 ms 246972 KB Output is correct
117 Correct 307 ms 246908 KB Output is correct
118 Correct 313 ms 246984 KB Output is correct
119 Correct 310 ms 246960 KB Output is correct
120 Correct 282 ms 202160 KB Output is correct
121 Correct 287 ms 202036 KB Output is correct
122 Correct 297 ms 202016 KB Output is correct
123 Correct 314 ms 202032 KB Output is correct
124 Correct 283 ms 229464 KB Output is correct
125 Correct 281 ms 229348 KB Output is correct
126 Correct 281 ms 229388 KB Output is correct
127 Correct 285 ms 229412 KB Output is correct
128 Correct 172 ms 161996 KB Output is correct
129 Correct 180 ms 161968 KB Output is correct
130 Correct 161 ms 162096 KB Output is correct
131 Correct 60 ms 117848 KB Output is correct