답안 #990860

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
990860 2024-05-31T14:23:58 Z Savu_Stefan_Catalin Homework (CEOI22_homework) C++14
100 / 100
163 ms 236884 KB
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
const int NMAX=3e6+5;
int leaf[NMAX+5],sz[NMAX+5],st[NMAX+5],dr[NMAX+5],t[NMAX+5],vv[NMAX+5];
char s[3*NMAX+5];
vector <int> v[NMAX+5];
void dfs(int nod)
{
    if (leaf[nod]==1) {sz[nod]=1; st[nod]=1; dr[nod]=1; return ;}
    for (int i=0;i<2;++i)
    {
        dfs(v[nod][i]);
        sz[nod]+=sz[v[nod][i]];
    }
    int s=v[nod][0],d=v[nod][1];
    if (vv[nod]==0)
    {
        st[nod]=min(st[s],st[d]);
        dr[nod]=dr[s]+dr[d]-1;
    }
    else
    {
        st[nod]=st[s]+st[d];
        dr[nod]=max(dr[s]+sz[d],dr[d]+sz[s]);
    }
}
int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(0);
    cout.tie(0);
    cin.getline(s,8e6);
    int n=strlen(s);
    int p=0;
    int nod=0,cnt=0;
    while (true)
    {
        int val=0;
        if (s[p]=='m')
        {
            if (s[p+1]=='i') val=0;
            else val=1;
            cnt++;
            t[cnt]=nod;
            vv[cnt]=val;
            nod=cnt;
            p+=4;
        }
        else if (s[p]=='?')
        {
            cnt++;
            t[cnt]=nod;
            leaf[cnt]=1;
            p++;
        }
        else if (s[p]==')') {nod=t[nod]; p++;}
        else if (s[p]==',') p++;
        else break;
    }
    for (int i=1;i<=cnt;++i)
    {
        v[t[i]].push_back(i);
    }
    dfs(1);
    cout<<dr[1]-st[1]+1;
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:35:9: warning: unused variable 'n' [-Wunused-variable]
   35 |     int n=strlen(s);
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 84568 KB Output is correct
2 Correct 14 ms 84572 KB Output is correct
3 Correct 14 ms 84608 KB Output is correct
4 Correct 14 ms 84572 KB Output is correct
5 Correct 13 ms 84568 KB Output is correct
6 Correct 13 ms 84568 KB Output is correct
7 Correct 14 ms 84572 KB Output is correct
8 Correct 13 ms 84572 KB Output is correct
9 Correct 13 ms 84572 KB Output is correct
10 Correct 13 ms 84572 KB Output is correct
11 Correct 13 ms 84572 KB Output is correct
12 Correct 13 ms 84568 KB Output is correct
13 Correct 13 ms 84568 KB Output is correct
14 Correct 13 ms 84656 KB Output is correct
15 Correct 13 ms 84572 KB Output is correct
16 Correct 15 ms 84572 KB Output is correct
17 Correct 14 ms 84776 KB Output is correct
18 Correct 14 ms 84568 KB Output is correct
19 Correct 13 ms 84572 KB Output is correct
20 Correct 13 ms 84572 KB Output is correct
21 Correct 14 ms 84712 KB Output is correct
22 Correct 14 ms 84672 KB Output is correct
23 Correct 13 ms 84572 KB Output is correct
24 Correct 13 ms 84572 KB Output is correct
25 Correct 13 ms 84568 KB Output is correct
26 Correct 13 ms 84572 KB Output is correct
27 Correct 13 ms 84572 KB Output is correct
28 Correct 14 ms 84572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 84568 KB Output is correct
2 Correct 14 ms 84572 KB Output is correct
3 Correct 14 ms 84608 KB Output is correct
4 Correct 14 ms 84572 KB Output is correct
5 Correct 13 ms 84568 KB Output is correct
6 Correct 13 ms 84568 KB Output is correct
7 Correct 14 ms 84572 KB Output is correct
8 Correct 13 ms 84572 KB Output is correct
9 Correct 13 ms 84572 KB Output is correct
10 Correct 13 ms 84572 KB Output is correct
11 Correct 13 ms 84572 KB Output is correct
12 Correct 13 ms 84568 KB Output is correct
13 Correct 13 ms 84568 KB Output is correct
14 Correct 13 ms 84656 KB Output is correct
15 Correct 13 ms 84572 KB Output is correct
16 Correct 15 ms 84572 KB Output is correct
17 Correct 14 ms 84776 KB Output is correct
18 Correct 14 ms 84568 KB Output is correct
19 Correct 13 ms 84572 KB Output is correct
20 Correct 13 ms 84572 KB Output is correct
21 Correct 14 ms 84712 KB Output is correct
22 Correct 14 ms 84672 KB Output is correct
23 Correct 13 ms 84572 KB Output is correct
24 Correct 13 ms 84572 KB Output is correct
25 Correct 13 ms 84568 KB Output is correct
26 Correct 13 ms 84572 KB Output is correct
27 Correct 13 ms 84572 KB Output is correct
28 Correct 14 ms 84572 KB Output is correct
29 Correct 13 ms 84572 KB Output is correct
30 Correct 13 ms 84572 KB Output is correct
31 Correct 13 ms 84572 KB Output is correct
32 Correct 13 ms 84572 KB Output is correct
33 Correct 12 ms 84572 KB Output is correct
34 Correct 13 ms 84776 KB Output is correct
35 Correct 14 ms 84572 KB Output is correct
36 Correct 13 ms 84572 KB Output is correct
37 Correct 13 ms 84568 KB Output is correct
38 Correct 14 ms 84568 KB Output is correct
39 Correct 13 ms 84568 KB Output is correct
40 Correct 13 ms 84572 KB Output is correct
41 Correct 13 ms 84572 KB Output is correct
42 Correct 14 ms 84568 KB Output is correct
43 Correct 14 ms 84688 KB Output is correct
44 Correct 12 ms 84772 KB Output is correct
45 Correct 13 ms 84572 KB Output is correct
46 Correct 14 ms 84688 KB Output is correct
47 Correct 14 ms 84568 KB Output is correct
48 Correct 13 ms 84568 KB Output is correct
49 Correct 13 ms 84772 KB Output is correct
50 Correct 13 ms 84568 KB Output is correct
51 Correct 13 ms 84568 KB Output is correct
52 Correct 13 ms 84572 KB Output is correct
53 Correct 14 ms 84764 KB Output is correct
54 Correct 14 ms 84568 KB Output is correct
55 Correct 13 ms 84576 KB Output is correct
56 Correct 13 ms 84572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 163 ms 236304 KB Output is correct
2 Correct 151 ms 236772 KB Output is correct
3 Correct 153 ms 236884 KB Output is correct
4 Correct 160 ms 236652 KB Output is correct
5 Correct 148 ms 236628 KB Output is correct
6 Correct 153 ms 236776 KB Output is correct
7 Correct 150 ms 236632 KB Output is correct
8 Correct 153 ms 236656 KB Output is correct
9 Correct 157 ms 236628 KB Output is correct
10 Correct 153 ms 236628 KB Output is correct
11 Correct 153 ms 236780 KB Output is correct
12 Correct 152 ms 236656 KB Output is correct
13 Correct 13 ms 84572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 84568 KB Output is correct
2 Correct 14 ms 84572 KB Output is correct
3 Correct 14 ms 84608 KB Output is correct
4 Correct 14 ms 84572 KB Output is correct
5 Correct 13 ms 84568 KB Output is correct
6 Correct 13 ms 84568 KB Output is correct
7 Correct 14 ms 84572 KB Output is correct
8 Correct 13 ms 84572 KB Output is correct
9 Correct 13 ms 84572 KB Output is correct
10 Correct 13 ms 84572 KB Output is correct
11 Correct 13 ms 84572 KB Output is correct
12 Correct 13 ms 84568 KB Output is correct
13 Correct 13 ms 84568 KB Output is correct
14 Correct 13 ms 84656 KB Output is correct
15 Correct 13 ms 84572 KB Output is correct
16 Correct 15 ms 84572 KB Output is correct
17 Correct 14 ms 84776 KB Output is correct
18 Correct 14 ms 84568 KB Output is correct
19 Correct 13 ms 84572 KB Output is correct
20 Correct 13 ms 84572 KB Output is correct
21 Correct 14 ms 84712 KB Output is correct
22 Correct 14 ms 84672 KB Output is correct
23 Correct 13 ms 84572 KB Output is correct
24 Correct 13 ms 84572 KB Output is correct
25 Correct 13 ms 84568 KB Output is correct
26 Correct 13 ms 84572 KB Output is correct
27 Correct 13 ms 84572 KB Output is correct
28 Correct 14 ms 84572 KB Output is correct
29 Correct 13 ms 84572 KB Output is correct
30 Correct 13 ms 84572 KB Output is correct
31 Correct 13 ms 84572 KB Output is correct
32 Correct 13 ms 84572 KB Output is correct
33 Correct 12 ms 84572 KB Output is correct
34 Correct 13 ms 84776 KB Output is correct
35 Correct 14 ms 84572 KB Output is correct
36 Correct 13 ms 84572 KB Output is correct
37 Correct 13 ms 84568 KB Output is correct
38 Correct 14 ms 84568 KB Output is correct
39 Correct 13 ms 84568 KB Output is correct
40 Correct 13 ms 84572 KB Output is correct
41 Correct 13 ms 84572 KB Output is correct
42 Correct 14 ms 84568 KB Output is correct
43 Correct 14 ms 84688 KB Output is correct
44 Correct 12 ms 84772 KB Output is correct
45 Correct 13 ms 84572 KB Output is correct
46 Correct 14 ms 84688 KB Output is correct
47 Correct 14 ms 84568 KB Output is correct
48 Correct 13 ms 84568 KB Output is correct
49 Correct 13 ms 84772 KB Output is correct
50 Correct 13 ms 84568 KB Output is correct
51 Correct 13 ms 84568 KB Output is correct
52 Correct 13 ms 84572 KB Output is correct
53 Correct 14 ms 84764 KB Output is correct
54 Correct 14 ms 84568 KB Output is correct
55 Correct 13 ms 84576 KB Output is correct
56 Correct 13 ms 84572 KB Output is correct
57 Correct 13 ms 84572 KB Output is correct
58 Correct 14 ms 84676 KB Output is correct
59 Correct 13 ms 84672 KB Output is correct
60 Correct 13 ms 84568 KB Output is correct
61 Correct 13 ms 84568 KB Output is correct
62 Correct 13 ms 84572 KB Output is correct
63 Correct 13 ms 84832 KB Output is correct
64 Correct 13 ms 84828 KB Output is correct
65 Correct 14 ms 84828 KB Output is correct
66 Correct 13 ms 84828 KB Output is correct
67 Correct 13 ms 84572 KB Output is correct
68 Correct 13 ms 84572 KB Output is correct
69 Correct 13 ms 84572 KB Output is correct
70 Correct 13 ms 84752 KB Output is correct
71 Correct 13 ms 84572 KB Output is correct
72 Correct 13 ms 84768 KB Output is correct
73 Correct 13 ms 84828 KB Output is correct
74 Correct 13 ms 84824 KB Output is correct
75 Correct 13 ms 84864 KB Output is correct
76 Correct 14 ms 84828 KB Output is correct
77 Correct 13 ms 84572 KB Output is correct
78 Correct 13 ms 84568 KB Output is correct
79 Correct 12 ms 84692 KB Output is correct
80 Correct 13 ms 84696 KB Output is correct
81 Correct 13 ms 84840 KB Output is correct
82 Correct 13 ms 84828 KB Output is correct
83 Correct 13 ms 84568 KB Output is correct
84 Correct 13 ms 84572 KB Output is correct
85 Correct 13 ms 84572 KB Output is correct
86 Correct 13 ms 84572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 84568 KB Output is correct
2 Correct 14 ms 84572 KB Output is correct
3 Correct 14 ms 84608 KB Output is correct
4 Correct 14 ms 84572 KB Output is correct
5 Correct 13 ms 84568 KB Output is correct
6 Correct 13 ms 84568 KB Output is correct
7 Correct 14 ms 84572 KB Output is correct
8 Correct 13 ms 84572 KB Output is correct
9 Correct 13 ms 84572 KB Output is correct
10 Correct 13 ms 84572 KB Output is correct
11 Correct 13 ms 84572 KB Output is correct
12 Correct 13 ms 84568 KB Output is correct
13 Correct 13 ms 84568 KB Output is correct
14 Correct 13 ms 84656 KB Output is correct
15 Correct 13 ms 84572 KB Output is correct
16 Correct 15 ms 84572 KB Output is correct
17 Correct 14 ms 84776 KB Output is correct
18 Correct 14 ms 84568 KB Output is correct
19 Correct 13 ms 84572 KB Output is correct
20 Correct 13 ms 84572 KB Output is correct
21 Correct 14 ms 84712 KB Output is correct
22 Correct 14 ms 84672 KB Output is correct
23 Correct 13 ms 84572 KB Output is correct
24 Correct 13 ms 84572 KB Output is correct
25 Correct 13 ms 84568 KB Output is correct
26 Correct 13 ms 84572 KB Output is correct
27 Correct 13 ms 84572 KB Output is correct
28 Correct 14 ms 84572 KB Output is correct
29 Correct 13 ms 84572 KB Output is correct
30 Correct 13 ms 84572 KB Output is correct
31 Correct 13 ms 84572 KB Output is correct
32 Correct 13 ms 84572 KB Output is correct
33 Correct 12 ms 84572 KB Output is correct
34 Correct 13 ms 84776 KB Output is correct
35 Correct 14 ms 84572 KB Output is correct
36 Correct 13 ms 84572 KB Output is correct
37 Correct 13 ms 84568 KB Output is correct
38 Correct 14 ms 84568 KB Output is correct
39 Correct 13 ms 84568 KB Output is correct
40 Correct 13 ms 84572 KB Output is correct
41 Correct 13 ms 84572 KB Output is correct
42 Correct 14 ms 84568 KB Output is correct
43 Correct 14 ms 84688 KB Output is correct
44 Correct 12 ms 84772 KB Output is correct
45 Correct 13 ms 84572 KB Output is correct
46 Correct 14 ms 84688 KB Output is correct
47 Correct 14 ms 84568 KB Output is correct
48 Correct 13 ms 84568 KB Output is correct
49 Correct 13 ms 84772 KB Output is correct
50 Correct 13 ms 84568 KB Output is correct
51 Correct 13 ms 84568 KB Output is correct
52 Correct 13 ms 84572 KB Output is correct
53 Correct 14 ms 84764 KB Output is correct
54 Correct 14 ms 84568 KB Output is correct
55 Correct 13 ms 84576 KB Output is correct
56 Correct 13 ms 84572 KB Output is correct
57 Correct 163 ms 236304 KB Output is correct
58 Correct 151 ms 236772 KB Output is correct
59 Correct 153 ms 236884 KB Output is correct
60 Correct 160 ms 236652 KB Output is correct
61 Correct 148 ms 236628 KB Output is correct
62 Correct 153 ms 236776 KB Output is correct
63 Correct 150 ms 236632 KB Output is correct
64 Correct 153 ms 236656 KB Output is correct
65 Correct 157 ms 236628 KB Output is correct
66 Correct 153 ms 236628 KB Output is correct
67 Correct 153 ms 236780 KB Output is correct
68 Correct 152 ms 236656 KB Output is correct
69 Correct 13 ms 84572 KB Output is correct
70 Correct 13 ms 84572 KB Output is correct
71 Correct 14 ms 84676 KB Output is correct
72 Correct 13 ms 84672 KB Output is correct
73 Correct 13 ms 84568 KB Output is correct
74 Correct 13 ms 84568 KB Output is correct
75 Correct 13 ms 84572 KB Output is correct
76 Correct 13 ms 84832 KB Output is correct
77 Correct 13 ms 84828 KB Output is correct
78 Correct 14 ms 84828 KB Output is correct
79 Correct 13 ms 84828 KB Output is correct
80 Correct 13 ms 84572 KB Output is correct
81 Correct 13 ms 84572 KB Output is correct
82 Correct 13 ms 84572 KB Output is correct
83 Correct 13 ms 84752 KB Output is correct
84 Correct 13 ms 84572 KB Output is correct
85 Correct 13 ms 84768 KB Output is correct
86 Correct 13 ms 84828 KB Output is correct
87 Correct 13 ms 84824 KB Output is correct
88 Correct 13 ms 84864 KB Output is correct
89 Correct 14 ms 84828 KB Output is correct
90 Correct 13 ms 84572 KB Output is correct
91 Correct 13 ms 84568 KB Output is correct
92 Correct 12 ms 84692 KB Output is correct
93 Correct 13 ms 84696 KB Output is correct
94 Correct 13 ms 84840 KB Output is correct
95 Correct 13 ms 84828 KB Output is correct
96 Correct 13 ms 84568 KB Output is correct
97 Correct 13 ms 84572 KB Output is correct
98 Correct 13 ms 84572 KB Output is correct
99 Correct 13 ms 84572 KB Output is correct
100 Correct 123 ms 176252 KB Output is correct
101 Correct 120 ms 176244 KB Output is correct
102 Correct 112 ms 176064 KB Output is correct
103 Correct 110 ms 176232 KB Output is correct
104 Correct 107 ms 176112 KB Output is correct
105 Correct 138 ms 197208 KB Output is correct
106 Correct 135 ms 196980 KB Output is correct
107 Correct 128 ms 196996 KB Output is correct
108 Correct 133 ms 196976 KB Output is correct
109 Correct 128 ms 197120 KB Output is correct
110 Correct 120 ms 176112 KB Output is correct
111 Correct 112 ms 176212 KB Output is correct
112 Correct 123 ms 176240 KB Output is correct
113 Correct 113 ms 176212 KB Output is correct
114 Correct 113 ms 176208 KB Output is correct
115 Correct 155 ms 236668 KB Output is correct
116 Correct 151 ms 236628 KB Output is correct
117 Correct 149 ms 236628 KB Output is correct
118 Correct 146 ms 236628 KB Output is correct
119 Correct 147 ms 236780 KB Output is correct
120 Correct 112 ms 176252 KB Output is correct
121 Correct 110 ms 176208 KB Output is correct
122 Correct 121 ms 176212 KB Output is correct
123 Correct 117 ms 176212 KB Output is correct
124 Correct 118 ms 207488 KB Output is correct
125 Correct 122 ms 207320 KB Output is correct
126 Correct 124 ms 207544 KB Output is correct
127 Correct 120 ms 207440 KB Output is correct
128 Correct 55 ms 131412 KB Output is correct
129 Correct 53 ms 131192 KB Output is correct
130 Correct 58 ms 131408 KB Output is correct
131 Correct 13 ms 84572 KB Output is correct