답안 #956815

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
956815 2024-04-02T13:53:33 Z Lukap Homework (CEOI22_homework) C++14
100 / 100
151 ms 184724 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2e6;

string s;
int n, uk;
int l[MAXN], r[MAXN], tip[MAXN], lo[MAXN], hi[MAXN], vel[MAXN];
vector<int> v;
vector<int> zarez[MAXN];
int koji[MAXN];

void unos (int l_g, int r_g, int xi) {
    int x = uk;
    uk++;
    if (r_g == l_g) {
        n++;
        return;
    }

    char a = s[l_g + 1];

    int zag = zarez[xi][koji[xi]];
    koji[xi]++;

    if (a == 'i') tip[x] = 0;
    else tip[x] = 1;

    l[x] = uk;
    unos (l_g + 4, zag - 1, xi + 1);

    r[x] = uk;
    unos (zag + 1, r_g - 1, xi + 1);

}

void dfs (int x) {
    if (l[x] == -1) {
        vel[x] = 1;
        lo[x] = 1;
        hi[x] = 1;
        return;
    }

    dfs (l[x]);
    dfs (r[x]);

    vel[x] = vel[l[x]] + vel[r[x]];

    if (!tip[x]) {
        lo[x] = min (lo[l[x]], lo[r[x]]);
        hi[x] = hi[l[x]] + hi[r[x]] - 1;
    }
    else {
        lo[x] = lo[l[x]] + lo[r[x]];
        hi[x] = max (hi[l[x]] + vel[r[x]], hi[r[x]] + vel[l[x]]);
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie (0);
    cout.tie (0);
    memset (l , -1, sizeof (l));
    memset (r, -1, sizeof (r));

    cin >> s;
    int brojem = 0;
    for (int i = 0; i < (int) s.size (); i++) {
        if (s[i] == '(') brojem++;
        if (s[i] == ')') brojem--;
        if (s[i] == ',') zarez[brojem - 1].push_back (i);
    }
    unos (0, s.size () - 1, 0);

    dfs (0);

    cout << hi[0] - lo[0] + 1;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 73304 KB Output is correct
2 Correct 15 ms 73308 KB Output is correct
3 Correct 15 ms 73308 KB Output is correct
4 Correct 15 ms 73304 KB Output is correct
5 Correct 15 ms 73308 KB Output is correct
6 Correct 15 ms 73308 KB Output is correct
7 Correct 15 ms 73308 KB Output is correct
8 Correct 15 ms 73308 KB Output is correct
9 Correct 15 ms 73188 KB Output is correct
10 Correct 15 ms 73308 KB Output is correct
11 Correct 14 ms 73304 KB Output is correct
12 Correct 16 ms 73308 KB Output is correct
13 Correct 15 ms 73308 KB Output is correct
14 Correct 16 ms 73304 KB Output is correct
15 Correct 14 ms 73308 KB Output is correct
16 Correct 15 ms 73308 KB Output is correct
17 Correct 15 ms 73308 KB Output is correct
18 Correct 15 ms 73308 KB Output is correct
19 Correct 15 ms 73180 KB Output is correct
20 Correct 14 ms 73316 KB Output is correct
21 Correct 14 ms 73308 KB Output is correct
22 Correct 14 ms 73200 KB Output is correct
23 Correct 15 ms 73304 KB Output is correct
24 Correct 15 ms 73308 KB Output is correct
25 Correct 16 ms 73564 KB Output is correct
26 Correct 15 ms 73316 KB Output is correct
27 Correct 15 ms 73308 KB Output is correct
28 Correct 14 ms 73308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 73304 KB Output is correct
2 Correct 15 ms 73308 KB Output is correct
3 Correct 15 ms 73308 KB Output is correct
4 Correct 15 ms 73304 KB Output is correct
5 Correct 15 ms 73308 KB Output is correct
6 Correct 15 ms 73308 KB Output is correct
7 Correct 15 ms 73308 KB Output is correct
8 Correct 15 ms 73308 KB Output is correct
9 Correct 15 ms 73188 KB Output is correct
10 Correct 15 ms 73308 KB Output is correct
11 Correct 14 ms 73304 KB Output is correct
12 Correct 16 ms 73308 KB Output is correct
13 Correct 15 ms 73308 KB Output is correct
14 Correct 16 ms 73304 KB Output is correct
15 Correct 14 ms 73308 KB Output is correct
16 Correct 15 ms 73308 KB Output is correct
17 Correct 15 ms 73308 KB Output is correct
18 Correct 15 ms 73308 KB Output is correct
19 Correct 15 ms 73180 KB Output is correct
20 Correct 14 ms 73316 KB Output is correct
21 Correct 14 ms 73308 KB Output is correct
22 Correct 14 ms 73200 KB Output is correct
23 Correct 15 ms 73304 KB Output is correct
24 Correct 15 ms 73308 KB Output is correct
25 Correct 16 ms 73564 KB Output is correct
26 Correct 15 ms 73316 KB Output is correct
27 Correct 15 ms 73308 KB Output is correct
28 Correct 14 ms 73308 KB Output is correct
29 Correct 14 ms 73308 KB Output is correct
30 Correct 14 ms 73308 KB Output is correct
31 Correct 15 ms 73308 KB Output is correct
32 Correct 15 ms 73308 KB Output is correct
33 Correct 15 ms 73560 KB Output is correct
34 Correct 14 ms 73200 KB Output is correct
35 Correct 15 ms 73292 KB Output is correct
36 Correct 15 ms 73304 KB Output is correct
37 Correct 15 ms 73308 KB Output is correct
38 Correct 15 ms 73304 KB Output is correct
39 Correct 14 ms 73308 KB Output is correct
40 Correct 14 ms 73228 KB Output is correct
41 Correct 16 ms 73264 KB Output is correct
42 Correct 15 ms 73288 KB Output is correct
43 Correct 15 ms 73308 KB Output is correct
44 Correct 15 ms 73308 KB Output is correct
45 Correct 15 ms 73308 KB Output is correct
46 Correct 15 ms 73308 KB Output is correct
47 Correct 14 ms 73308 KB Output is correct
48 Correct 15 ms 73308 KB Output is correct
49 Correct 15 ms 73308 KB Output is correct
50 Correct 15 ms 73308 KB Output is correct
51 Correct 15 ms 73304 KB Output is correct
52 Correct 15 ms 73308 KB Output is correct
53 Correct 15 ms 73308 KB Output is correct
54 Correct 15 ms 73552 KB Output is correct
55 Correct 14 ms 73304 KB Output is correct
56 Correct 14 ms 73308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 183912 KB Output is correct
2 Correct 151 ms 184276 KB Output is correct
3 Correct 150 ms 184320 KB Output is correct
4 Correct 151 ms 183608 KB Output is correct
5 Correct 146 ms 184384 KB Output is correct
6 Correct 145 ms 183504 KB Output is correct
7 Correct 148 ms 184004 KB Output is correct
8 Correct 145 ms 183460 KB Output is correct
9 Correct 144 ms 183500 KB Output is correct
10 Correct 145 ms 184596 KB Output is correct
11 Correct 144 ms 183596 KB Output is correct
12 Correct 146 ms 183244 KB Output is correct
13 Correct 16 ms 73552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 73304 KB Output is correct
2 Correct 15 ms 73308 KB Output is correct
3 Correct 15 ms 73308 KB Output is correct
4 Correct 15 ms 73304 KB Output is correct
5 Correct 15 ms 73308 KB Output is correct
6 Correct 15 ms 73308 KB Output is correct
7 Correct 15 ms 73308 KB Output is correct
8 Correct 15 ms 73308 KB Output is correct
9 Correct 15 ms 73188 KB Output is correct
10 Correct 15 ms 73308 KB Output is correct
11 Correct 14 ms 73304 KB Output is correct
12 Correct 16 ms 73308 KB Output is correct
13 Correct 15 ms 73308 KB Output is correct
14 Correct 16 ms 73304 KB Output is correct
15 Correct 14 ms 73308 KB Output is correct
16 Correct 15 ms 73308 KB Output is correct
17 Correct 15 ms 73308 KB Output is correct
18 Correct 15 ms 73308 KB Output is correct
19 Correct 15 ms 73180 KB Output is correct
20 Correct 14 ms 73316 KB Output is correct
21 Correct 14 ms 73308 KB Output is correct
22 Correct 14 ms 73200 KB Output is correct
23 Correct 15 ms 73304 KB Output is correct
24 Correct 15 ms 73308 KB Output is correct
25 Correct 16 ms 73564 KB Output is correct
26 Correct 15 ms 73316 KB Output is correct
27 Correct 15 ms 73308 KB Output is correct
28 Correct 14 ms 73308 KB Output is correct
29 Correct 14 ms 73308 KB Output is correct
30 Correct 14 ms 73308 KB Output is correct
31 Correct 15 ms 73308 KB Output is correct
32 Correct 15 ms 73308 KB Output is correct
33 Correct 15 ms 73560 KB Output is correct
34 Correct 14 ms 73200 KB Output is correct
35 Correct 15 ms 73292 KB Output is correct
36 Correct 15 ms 73304 KB Output is correct
37 Correct 15 ms 73308 KB Output is correct
38 Correct 15 ms 73304 KB Output is correct
39 Correct 14 ms 73308 KB Output is correct
40 Correct 14 ms 73228 KB Output is correct
41 Correct 16 ms 73264 KB Output is correct
42 Correct 15 ms 73288 KB Output is correct
43 Correct 15 ms 73308 KB Output is correct
44 Correct 15 ms 73308 KB Output is correct
45 Correct 15 ms 73308 KB Output is correct
46 Correct 15 ms 73308 KB Output is correct
47 Correct 14 ms 73308 KB Output is correct
48 Correct 15 ms 73308 KB Output is correct
49 Correct 15 ms 73308 KB Output is correct
50 Correct 15 ms 73308 KB Output is correct
51 Correct 15 ms 73304 KB Output is correct
52 Correct 15 ms 73308 KB Output is correct
53 Correct 15 ms 73308 KB Output is correct
54 Correct 15 ms 73552 KB Output is correct
55 Correct 14 ms 73304 KB Output is correct
56 Correct 14 ms 73308 KB Output is correct
57 Correct 15 ms 73312 KB Output is correct
58 Correct 15 ms 73308 KB Output is correct
59 Correct 15 ms 73308 KB Output is correct
60 Correct 15 ms 73560 KB Output is correct
61 Correct 15 ms 73308 KB Output is correct
62 Correct 15 ms 73352 KB Output is correct
63 Correct 15 ms 73308 KB Output is correct
64 Correct 15 ms 73308 KB Output is correct
65 Correct 15 ms 73356 KB Output is correct
66 Correct 15 ms 73308 KB Output is correct
67 Correct 15 ms 73304 KB Output is correct
68 Correct 15 ms 73308 KB Output is correct
69 Correct 14 ms 73308 KB Output is correct
70 Correct 15 ms 73308 KB Output is correct
71 Correct 15 ms 73304 KB Output is correct
72 Correct 15 ms 73308 KB Output is correct
73 Correct 15 ms 73304 KB Output is correct
74 Correct 16 ms 73308 KB Output is correct
75 Correct 15 ms 73556 KB Output is correct
76 Correct 14 ms 73308 KB Output is correct
77 Correct 15 ms 73220 KB Output is correct
78 Correct 16 ms 73196 KB Output is correct
79 Correct 15 ms 73308 KB Output is correct
80 Correct 14 ms 73304 KB Output is correct
81 Correct 15 ms 73300 KB Output is correct
82 Correct 14 ms 73308 KB Output is correct
83 Correct 15 ms 73308 KB Output is correct
84 Correct 15 ms 73304 KB Output is correct
85 Correct 15 ms 73308 KB Output is correct
86 Correct 15 ms 73308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 73304 KB Output is correct
2 Correct 15 ms 73308 KB Output is correct
3 Correct 15 ms 73308 KB Output is correct
4 Correct 15 ms 73304 KB Output is correct
5 Correct 15 ms 73308 KB Output is correct
6 Correct 15 ms 73308 KB Output is correct
7 Correct 15 ms 73308 KB Output is correct
8 Correct 15 ms 73308 KB Output is correct
9 Correct 15 ms 73188 KB Output is correct
10 Correct 15 ms 73308 KB Output is correct
11 Correct 14 ms 73304 KB Output is correct
12 Correct 16 ms 73308 KB Output is correct
13 Correct 15 ms 73308 KB Output is correct
14 Correct 16 ms 73304 KB Output is correct
15 Correct 14 ms 73308 KB Output is correct
16 Correct 15 ms 73308 KB Output is correct
17 Correct 15 ms 73308 KB Output is correct
18 Correct 15 ms 73308 KB Output is correct
19 Correct 15 ms 73180 KB Output is correct
20 Correct 14 ms 73316 KB Output is correct
21 Correct 14 ms 73308 KB Output is correct
22 Correct 14 ms 73200 KB Output is correct
23 Correct 15 ms 73304 KB Output is correct
24 Correct 15 ms 73308 KB Output is correct
25 Correct 16 ms 73564 KB Output is correct
26 Correct 15 ms 73316 KB Output is correct
27 Correct 15 ms 73308 KB Output is correct
28 Correct 14 ms 73308 KB Output is correct
29 Correct 14 ms 73308 KB Output is correct
30 Correct 14 ms 73308 KB Output is correct
31 Correct 15 ms 73308 KB Output is correct
32 Correct 15 ms 73308 KB Output is correct
33 Correct 15 ms 73560 KB Output is correct
34 Correct 14 ms 73200 KB Output is correct
35 Correct 15 ms 73292 KB Output is correct
36 Correct 15 ms 73304 KB Output is correct
37 Correct 15 ms 73308 KB Output is correct
38 Correct 15 ms 73304 KB Output is correct
39 Correct 14 ms 73308 KB Output is correct
40 Correct 14 ms 73228 KB Output is correct
41 Correct 16 ms 73264 KB Output is correct
42 Correct 15 ms 73288 KB Output is correct
43 Correct 15 ms 73308 KB Output is correct
44 Correct 15 ms 73308 KB Output is correct
45 Correct 15 ms 73308 KB Output is correct
46 Correct 15 ms 73308 KB Output is correct
47 Correct 14 ms 73308 KB Output is correct
48 Correct 15 ms 73308 KB Output is correct
49 Correct 15 ms 73308 KB Output is correct
50 Correct 15 ms 73308 KB Output is correct
51 Correct 15 ms 73304 KB Output is correct
52 Correct 15 ms 73308 KB Output is correct
53 Correct 15 ms 73308 KB Output is correct
54 Correct 15 ms 73552 KB Output is correct
55 Correct 14 ms 73304 KB Output is correct
56 Correct 14 ms 73308 KB Output is correct
57 Correct 147 ms 183912 KB Output is correct
58 Correct 151 ms 184276 KB Output is correct
59 Correct 150 ms 184320 KB Output is correct
60 Correct 151 ms 183608 KB Output is correct
61 Correct 146 ms 184384 KB Output is correct
62 Correct 145 ms 183504 KB Output is correct
63 Correct 148 ms 184004 KB Output is correct
64 Correct 145 ms 183460 KB Output is correct
65 Correct 144 ms 183500 KB Output is correct
66 Correct 145 ms 184596 KB Output is correct
67 Correct 144 ms 183596 KB Output is correct
68 Correct 146 ms 183244 KB Output is correct
69 Correct 16 ms 73552 KB Output is correct
70 Correct 15 ms 73312 KB Output is correct
71 Correct 15 ms 73308 KB Output is correct
72 Correct 15 ms 73308 KB Output is correct
73 Correct 15 ms 73560 KB Output is correct
74 Correct 15 ms 73308 KB Output is correct
75 Correct 15 ms 73352 KB Output is correct
76 Correct 15 ms 73308 KB Output is correct
77 Correct 15 ms 73308 KB Output is correct
78 Correct 15 ms 73356 KB Output is correct
79 Correct 15 ms 73308 KB Output is correct
80 Correct 15 ms 73304 KB Output is correct
81 Correct 15 ms 73308 KB Output is correct
82 Correct 14 ms 73308 KB Output is correct
83 Correct 15 ms 73308 KB Output is correct
84 Correct 15 ms 73304 KB Output is correct
85 Correct 15 ms 73308 KB Output is correct
86 Correct 15 ms 73304 KB Output is correct
87 Correct 16 ms 73308 KB Output is correct
88 Correct 15 ms 73556 KB Output is correct
89 Correct 14 ms 73308 KB Output is correct
90 Correct 15 ms 73220 KB Output is correct
91 Correct 16 ms 73196 KB Output is correct
92 Correct 15 ms 73308 KB Output is correct
93 Correct 14 ms 73304 KB Output is correct
94 Correct 15 ms 73300 KB Output is correct
95 Correct 14 ms 73308 KB Output is correct
96 Correct 15 ms 73308 KB Output is correct
97 Correct 15 ms 73304 KB Output is correct
98 Correct 15 ms 73308 KB Output is correct
99 Correct 15 ms 73308 KB Output is correct
100 Correct 79 ms 116432 KB Output is correct
101 Correct 79 ms 115208 KB Output is correct
102 Correct 76 ms 116796 KB Output is correct
103 Correct 77 ms 115336 KB Output is correct
104 Correct 74 ms 116432 KB Output is correct
105 Correct 119 ms 135728 KB Output is correct
106 Correct 119 ms 135888 KB Output is correct
107 Correct 114 ms 134744 KB Output is correct
108 Correct 115 ms 134760 KB Output is correct
109 Correct 116 ms 134608 KB Output is correct
110 Correct 83 ms 115152 KB Output is correct
111 Correct 84 ms 116668 KB Output is correct
112 Correct 80 ms 115892 KB Output is correct
113 Correct 81 ms 115124 KB Output is correct
114 Correct 81 ms 115404 KB Output is correct
115 Correct 148 ms 184268 KB Output is correct
116 Correct 146 ms 184280 KB Output is correct
117 Correct 143 ms 183824 KB Output is correct
118 Correct 150 ms 184724 KB Output is correct
119 Correct 147 ms 183756 KB Output is correct
120 Correct 81 ms 116076 KB Output is correct
121 Correct 81 ms 114932 KB Output is correct
122 Correct 85 ms 115616 KB Output is correct
123 Correct 85 ms 116148 KB Output is correct
124 Correct 96 ms 145872 KB Output is correct
125 Correct 95 ms 146628 KB Output is correct
126 Correct 94 ms 146092 KB Output is correct
127 Correct 92 ms 146616 KB Output is correct
128 Correct 41 ms 98780 KB Output is correct
129 Correct 41 ms 98772 KB Output is correct
130 Correct 42 ms 98916 KB Output is correct
131 Correct 15 ms 73304 KB Output is correct