답안 #688110

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
688110 2023-01-27T07:09:50 Z ksjsjsjsjsjsjs Homework (CEOI22_homework) C++14
100 / 100
209 ms 155076 KB
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define bg begin
#define ed end
#define ft front
#define bk back
#define ins insert
#define ers erase
#define sz(x) (int)(x).size()
#define all(x) (x).bg(), (x).ed()
#define mtp make_tuple
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define str string
#define pi pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define FOR(i, l, r) for (int i = (l); i <= (r); ++i)
#define FOS(i, r, l) for (int i = (r); i >= (l); --i)
#define FRN(i, n) for (int i = 0; i < (n); ++i)
#define FSN(i, n) for (int i = (n) - 1; i >= 0; --i)
#define EACH(i, x) for (auto &i : (x))
#define WHILE while
template<typename T> T gcd(T a, T b) { WHILE(b) { a %= b; swap(a, b); } return b; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
const int N = 2e6 + 5;
int n = 0, mm[N], s1[N];
str s;
vi adj[N];
bool valid(char c) { return (c >= 'a' && c <= 'z') || c == '?'; }
pi dfs(int u) {
    pi ans = {1, 1};
    if (!adj[u].empty()) {
        pi left = dfs(adj[u][0]), right = dfs(adj[u][1]);
        s1[u] = s1[adj[u][0]] + s1[adj[u][1]];
        if (mm[u] < 0) ans = {min(left.st, right.st), left.nd + right.nd - 1};
        else ans = {left.st + right.st, max(left.nd + s1[adj[u][1]], s1[adj[u][0]] + right.nd)};
    }
    else s1[u] = 1;
//    cerr << u << " : " << ans.st << ' ' << ans.nd << '\n';
    return ans;
}
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    freopen(file".inp", "r", stdin);
//    freopen(file".out", "w", stdout);
    cin >> s;
    stack<int> s1;
    FRN(i, sz(s)) {
        if (!valid(s[i])) continue;
        int j = i;
        WHILE(j < sz(s) && valid(s[j])) ++j;
        --j;
        ++n;
        if (!s1.empty()) {
            adj[s1.top()].pb(n);
            if (sz(adj[s1.top()]) == 2) s1.pop();
        }
        if (i == j) continue;
        if (s[i + 1] == 'a') mm[n] = 1;
        else mm[n] = -1;
        s1.push(n);
        i = j;
    }
//        cerr << i << " : ";
//        EACH(j, adj[i]) cerr << j << ' ';
//        cerr << '\n';
//    }
//    cerr << '\n';
    pi tmp = dfs(1);
    cout << tmp.nd - tmp.st + 1;
//    cerr << "\nTime: " << setprecision(5) << fixed << (ldb)clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47188 KB Output is correct
2 Correct 23 ms 47304 KB Output is correct
3 Correct 23 ms 47300 KB Output is correct
4 Correct 24 ms 47296 KB Output is correct
5 Correct 24 ms 47224 KB Output is correct
6 Correct 23 ms 47248 KB Output is correct
7 Correct 23 ms 47196 KB Output is correct
8 Correct 23 ms 47216 KB Output is correct
9 Correct 24 ms 47228 KB Output is correct
10 Correct 24 ms 47316 KB Output is correct
11 Correct 23 ms 47216 KB Output is correct
12 Correct 24 ms 47260 KB Output is correct
13 Correct 25 ms 47188 KB Output is correct
14 Correct 29 ms 47188 KB Output is correct
15 Correct 24 ms 47236 KB Output is correct
16 Correct 24 ms 47220 KB Output is correct
17 Correct 22 ms 47224 KB Output is correct
18 Correct 24 ms 47180 KB Output is correct
19 Correct 23 ms 47260 KB Output is correct
20 Correct 25 ms 47296 KB Output is correct
21 Correct 29 ms 47180 KB Output is correct
22 Correct 24 ms 47300 KB Output is correct
23 Correct 24 ms 47188 KB Output is correct
24 Correct 24 ms 47212 KB Output is correct
25 Correct 24 ms 47280 KB Output is correct
26 Correct 25 ms 47300 KB Output is correct
27 Correct 24 ms 47232 KB Output is correct
28 Correct 24 ms 47220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47188 KB Output is correct
2 Correct 23 ms 47304 KB Output is correct
3 Correct 23 ms 47300 KB Output is correct
4 Correct 24 ms 47296 KB Output is correct
5 Correct 24 ms 47224 KB Output is correct
6 Correct 23 ms 47248 KB Output is correct
7 Correct 23 ms 47196 KB Output is correct
8 Correct 23 ms 47216 KB Output is correct
9 Correct 24 ms 47228 KB Output is correct
10 Correct 24 ms 47316 KB Output is correct
11 Correct 23 ms 47216 KB Output is correct
12 Correct 24 ms 47260 KB Output is correct
13 Correct 25 ms 47188 KB Output is correct
14 Correct 29 ms 47188 KB Output is correct
15 Correct 24 ms 47236 KB Output is correct
16 Correct 24 ms 47220 KB Output is correct
17 Correct 22 ms 47224 KB Output is correct
18 Correct 24 ms 47180 KB Output is correct
19 Correct 23 ms 47260 KB Output is correct
20 Correct 25 ms 47296 KB Output is correct
21 Correct 29 ms 47180 KB Output is correct
22 Correct 24 ms 47300 KB Output is correct
23 Correct 24 ms 47188 KB Output is correct
24 Correct 24 ms 47212 KB Output is correct
25 Correct 24 ms 47280 KB Output is correct
26 Correct 25 ms 47300 KB Output is correct
27 Correct 24 ms 47232 KB Output is correct
28 Correct 24 ms 47220 KB Output is correct
29 Correct 23 ms 47188 KB Output is correct
30 Correct 27 ms 47200 KB Output is correct
31 Correct 22 ms 47308 KB Output is correct
32 Correct 23 ms 47224 KB Output is correct
33 Correct 23 ms 47296 KB Output is correct
34 Correct 28 ms 47204 KB Output is correct
35 Correct 23 ms 47188 KB Output is correct
36 Correct 23 ms 47188 KB Output is correct
37 Correct 23 ms 47244 KB Output is correct
38 Correct 24 ms 47240 KB Output is correct
39 Correct 23 ms 47196 KB Output is correct
40 Correct 23 ms 47232 KB Output is correct
41 Correct 24 ms 47188 KB Output is correct
42 Correct 25 ms 47224 KB Output is correct
43 Correct 24 ms 47268 KB Output is correct
44 Correct 24 ms 47304 KB Output is correct
45 Correct 23 ms 47272 KB Output is correct
46 Correct 25 ms 47276 KB Output is correct
47 Correct 23 ms 47208 KB Output is correct
48 Correct 24 ms 47188 KB Output is correct
49 Correct 24 ms 47248 KB Output is correct
50 Correct 25 ms 47200 KB Output is correct
51 Correct 24 ms 47188 KB Output is correct
52 Correct 26 ms 47188 KB Output is correct
53 Correct 23 ms 47276 KB Output is correct
54 Correct 24 ms 47248 KB Output is correct
55 Correct 24 ms 47272 KB Output is correct
56 Correct 25 ms 47176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 183 ms 154892 KB Output is correct
2 Correct 194 ms 155076 KB Output is correct
3 Correct 194 ms 154908 KB Output is correct
4 Correct 197 ms 154948 KB Output is correct
5 Correct 189 ms 154980 KB Output is correct
6 Correct 190 ms 154960 KB Output is correct
7 Correct 191 ms 154956 KB Output is correct
8 Correct 194 ms 154884 KB Output is correct
9 Correct 191 ms 154912 KB Output is correct
10 Correct 197 ms 155020 KB Output is correct
11 Correct 192 ms 154992 KB Output is correct
12 Correct 185 ms 154884 KB Output is correct
13 Correct 23 ms 47300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47188 KB Output is correct
2 Correct 23 ms 47304 KB Output is correct
3 Correct 23 ms 47300 KB Output is correct
4 Correct 24 ms 47296 KB Output is correct
5 Correct 24 ms 47224 KB Output is correct
6 Correct 23 ms 47248 KB Output is correct
7 Correct 23 ms 47196 KB Output is correct
8 Correct 23 ms 47216 KB Output is correct
9 Correct 24 ms 47228 KB Output is correct
10 Correct 24 ms 47316 KB Output is correct
11 Correct 23 ms 47216 KB Output is correct
12 Correct 24 ms 47260 KB Output is correct
13 Correct 25 ms 47188 KB Output is correct
14 Correct 29 ms 47188 KB Output is correct
15 Correct 24 ms 47236 KB Output is correct
16 Correct 24 ms 47220 KB Output is correct
17 Correct 22 ms 47224 KB Output is correct
18 Correct 24 ms 47180 KB Output is correct
19 Correct 23 ms 47260 KB Output is correct
20 Correct 25 ms 47296 KB Output is correct
21 Correct 29 ms 47180 KB Output is correct
22 Correct 24 ms 47300 KB Output is correct
23 Correct 24 ms 47188 KB Output is correct
24 Correct 24 ms 47212 KB Output is correct
25 Correct 24 ms 47280 KB Output is correct
26 Correct 25 ms 47300 KB Output is correct
27 Correct 24 ms 47232 KB Output is correct
28 Correct 24 ms 47220 KB Output is correct
29 Correct 23 ms 47188 KB Output is correct
30 Correct 27 ms 47200 KB Output is correct
31 Correct 22 ms 47308 KB Output is correct
32 Correct 23 ms 47224 KB Output is correct
33 Correct 23 ms 47296 KB Output is correct
34 Correct 28 ms 47204 KB Output is correct
35 Correct 23 ms 47188 KB Output is correct
36 Correct 23 ms 47188 KB Output is correct
37 Correct 23 ms 47244 KB Output is correct
38 Correct 24 ms 47240 KB Output is correct
39 Correct 23 ms 47196 KB Output is correct
40 Correct 23 ms 47232 KB Output is correct
41 Correct 24 ms 47188 KB Output is correct
42 Correct 25 ms 47224 KB Output is correct
43 Correct 24 ms 47268 KB Output is correct
44 Correct 24 ms 47304 KB Output is correct
45 Correct 23 ms 47272 KB Output is correct
46 Correct 25 ms 47276 KB Output is correct
47 Correct 23 ms 47208 KB Output is correct
48 Correct 24 ms 47188 KB Output is correct
49 Correct 24 ms 47248 KB Output is correct
50 Correct 25 ms 47200 KB Output is correct
51 Correct 24 ms 47188 KB Output is correct
52 Correct 26 ms 47188 KB Output is correct
53 Correct 23 ms 47276 KB Output is correct
54 Correct 24 ms 47248 KB Output is correct
55 Correct 24 ms 47272 KB Output is correct
56 Correct 25 ms 47176 KB Output is correct
57 Correct 23 ms 47316 KB Output is correct
58 Correct 23 ms 47316 KB Output is correct
59 Correct 23 ms 47344 KB Output is correct
60 Correct 24 ms 47308 KB Output is correct
61 Correct 24 ms 47300 KB Output is correct
62 Correct 23 ms 47316 KB Output is correct
63 Correct 23 ms 47292 KB Output is correct
64 Correct 26 ms 47296 KB Output is correct
65 Correct 23 ms 47312 KB Output is correct
66 Correct 25 ms 47332 KB Output is correct
67 Correct 23 ms 47292 KB Output is correct
68 Correct 23 ms 47308 KB Output is correct
69 Correct 23 ms 47340 KB Output is correct
70 Correct 24 ms 47308 KB Output is correct
71 Correct 27 ms 47316 KB Output is correct
72 Correct 24 ms 47316 KB Output is correct
73 Correct 23 ms 47360 KB Output is correct
74 Correct 23 ms 47284 KB Output is correct
75 Correct 23 ms 47292 KB Output is correct
76 Correct 24 ms 47316 KB Output is correct
77 Correct 24 ms 47316 KB Output is correct
78 Correct 23 ms 47308 KB Output is correct
79 Correct 26 ms 47384 KB Output is correct
80 Correct 26 ms 47292 KB Output is correct
81 Correct 24 ms 47392 KB Output is correct
82 Correct 24 ms 47308 KB Output is correct
83 Correct 24 ms 47320 KB Output is correct
84 Correct 23 ms 47244 KB Output is correct
85 Correct 30 ms 47204 KB Output is correct
86 Correct 28 ms 47228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47188 KB Output is correct
2 Correct 23 ms 47304 KB Output is correct
3 Correct 23 ms 47300 KB Output is correct
4 Correct 24 ms 47296 KB Output is correct
5 Correct 24 ms 47224 KB Output is correct
6 Correct 23 ms 47248 KB Output is correct
7 Correct 23 ms 47196 KB Output is correct
8 Correct 23 ms 47216 KB Output is correct
9 Correct 24 ms 47228 KB Output is correct
10 Correct 24 ms 47316 KB Output is correct
11 Correct 23 ms 47216 KB Output is correct
12 Correct 24 ms 47260 KB Output is correct
13 Correct 25 ms 47188 KB Output is correct
14 Correct 29 ms 47188 KB Output is correct
15 Correct 24 ms 47236 KB Output is correct
16 Correct 24 ms 47220 KB Output is correct
17 Correct 22 ms 47224 KB Output is correct
18 Correct 24 ms 47180 KB Output is correct
19 Correct 23 ms 47260 KB Output is correct
20 Correct 25 ms 47296 KB Output is correct
21 Correct 29 ms 47180 KB Output is correct
22 Correct 24 ms 47300 KB Output is correct
23 Correct 24 ms 47188 KB Output is correct
24 Correct 24 ms 47212 KB Output is correct
25 Correct 24 ms 47280 KB Output is correct
26 Correct 25 ms 47300 KB Output is correct
27 Correct 24 ms 47232 KB Output is correct
28 Correct 24 ms 47220 KB Output is correct
29 Correct 23 ms 47188 KB Output is correct
30 Correct 27 ms 47200 KB Output is correct
31 Correct 22 ms 47308 KB Output is correct
32 Correct 23 ms 47224 KB Output is correct
33 Correct 23 ms 47296 KB Output is correct
34 Correct 28 ms 47204 KB Output is correct
35 Correct 23 ms 47188 KB Output is correct
36 Correct 23 ms 47188 KB Output is correct
37 Correct 23 ms 47244 KB Output is correct
38 Correct 24 ms 47240 KB Output is correct
39 Correct 23 ms 47196 KB Output is correct
40 Correct 23 ms 47232 KB Output is correct
41 Correct 24 ms 47188 KB Output is correct
42 Correct 25 ms 47224 KB Output is correct
43 Correct 24 ms 47268 KB Output is correct
44 Correct 24 ms 47304 KB Output is correct
45 Correct 23 ms 47272 KB Output is correct
46 Correct 25 ms 47276 KB Output is correct
47 Correct 23 ms 47208 KB Output is correct
48 Correct 24 ms 47188 KB Output is correct
49 Correct 24 ms 47248 KB Output is correct
50 Correct 25 ms 47200 KB Output is correct
51 Correct 24 ms 47188 KB Output is correct
52 Correct 26 ms 47188 KB Output is correct
53 Correct 23 ms 47276 KB Output is correct
54 Correct 24 ms 47248 KB Output is correct
55 Correct 24 ms 47272 KB Output is correct
56 Correct 25 ms 47176 KB Output is correct
57 Correct 183 ms 154892 KB Output is correct
58 Correct 194 ms 155076 KB Output is correct
59 Correct 194 ms 154908 KB Output is correct
60 Correct 197 ms 154948 KB Output is correct
61 Correct 189 ms 154980 KB Output is correct
62 Correct 190 ms 154960 KB Output is correct
63 Correct 191 ms 154956 KB Output is correct
64 Correct 194 ms 154884 KB Output is correct
65 Correct 191 ms 154912 KB Output is correct
66 Correct 197 ms 155020 KB Output is correct
67 Correct 192 ms 154992 KB Output is correct
68 Correct 185 ms 154884 KB Output is correct
69 Correct 23 ms 47300 KB Output is correct
70 Correct 23 ms 47316 KB Output is correct
71 Correct 23 ms 47316 KB Output is correct
72 Correct 23 ms 47344 KB Output is correct
73 Correct 24 ms 47308 KB Output is correct
74 Correct 24 ms 47300 KB Output is correct
75 Correct 23 ms 47316 KB Output is correct
76 Correct 23 ms 47292 KB Output is correct
77 Correct 26 ms 47296 KB Output is correct
78 Correct 23 ms 47312 KB Output is correct
79 Correct 25 ms 47332 KB Output is correct
80 Correct 23 ms 47292 KB Output is correct
81 Correct 23 ms 47308 KB Output is correct
82 Correct 23 ms 47340 KB Output is correct
83 Correct 24 ms 47308 KB Output is correct
84 Correct 27 ms 47316 KB Output is correct
85 Correct 24 ms 47316 KB Output is correct
86 Correct 23 ms 47360 KB Output is correct
87 Correct 23 ms 47284 KB Output is correct
88 Correct 23 ms 47292 KB Output is correct
89 Correct 24 ms 47316 KB Output is correct
90 Correct 24 ms 47316 KB Output is correct
91 Correct 23 ms 47308 KB Output is correct
92 Correct 26 ms 47384 KB Output is correct
93 Correct 26 ms 47292 KB Output is correct
94 Correct 24 ms 47392 KB Output is correct
95 Correct 24 ms 47308 KB Output is correct
96 Correct 24 ms 47320 KB Output is correct
97 Correct 23 ms 47244 KB Output is correct
98 Correct 30 ms 47204 KB Output is correct
99 Correct 28 ms 47228 KB Output is correct
100 Correct 180 ms 107908 KB Output is correct
101 Correct 190 ms 107880 KB Output is correct
102 Correct 181 ms 107840 KB Output is correct
103 Correct 166 ms 107928 KB Output is correct
104 Correct 190 ms 107912 KB Output is correct
105 Correct 203 ms 123536 KB Output is correct
106 Correct 205 ms 123524 KB Output is correct
107 Correct 204 ms 123552 KB Output is correct
108 Correct 204 ms 123536 KB Output is correct
109 Correct 190 ms 123528 KB Output is correct
110 Correct 181 ms 107920 KB Output is correct
111 Correct 182 ms 107880 KB Output is correct
112 Correct 169 ms 107932 KB Output is correct
113 Correct 175 ms 107828 KB Output is correct
114 Correct 172 ms 107824 KB Output is correct
115 Correct 199 ms 154984 KB Output is correct
116 Correct 199 ms 154984 KB Output is correct
117 Correct 193 ms 154900 KB Output is correct
118 Correct 209 ms 154964 KB Output is correct
119 Correct 191 ms 154896 KB Output is correct
120 Correct 167 ms 107920 KB Output is correct
121 Correct 169 ms 107852 KB Output is correct
122 Correct 180 ms 107940 KB Output is correct
123 Correct 181 ms 107928 KB Output is correct
124 Correct 178 ms 131380 KB Output is correct
125 Correct 167 ms 131424 KB Output is correct
126 Correct 169 ms 131396 KB Output is correct
127 Correct 183 ms 131360 KB Output is correct
128 Correct 99 ms 79068 KB Output is correct
129 Correct 94 ms 79052 KB Output is correct
130 Correct 89 ms 78972 KB Output is correct
131 Correct 25 ms 47416 KB Output is correct