답안 #901604

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
901604 2024-01-09T16:41:24 Z Shayan86 Homework (CEOI22_homework) C++17
100 / 100
369 ms 292816 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// Ofast, O0, O1, O2, O3, unroll-loops, fast-math, trapv

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define Mp          make_pair
#define sep         ' '
#define endl        '\n'
#define F	        first
#define S	        second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define kill(res)	cout << res << '\n', exit(0);
#define set_dec(x)	cout << fixed << setprecision(x);
#define fast_io     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io     freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll N = 2e6 + 50;
const ll Mod = 1e9 + 7;

int n, m, k, vas[N], L[N], R[N];

string s;
vector<int> adj[N];

void dfs(int v, int p = 0){
    vector<int> ch;
    for(int u: adj[v]){
        if(u != p){
            dfs(u, v); ch.pb(u);
        }
    }
    if(ch.empty()){
        L[v] = 0; R[v] = 0;
        return;
    }

    if(vas[v]){
        R[v] = min(R[ch[0]], R[ch[1]]);
        L[v] = L[ch[0]] + L[ch[1]] + 1;
    }
    else{
        L[v] = min(L[ch[0]], L[ch[1]]);
        R[v] = R[ch[0]] + R[ch[1]] + 1;
    }
}

int main(){
    fast_io;

    cin >> s;
    m = s.size();

    vector<int> path;
    for(int i = 0; i < m;){
        if(s[i] == 'm'){
            int v = ++n;
            if(s[i+1] == 'a') vas[v] = 1;
            if(!path.empty()){
                int u = path.back();
                adj[u].pb(v);
                adj[v].pb(u);
            }
            path.pb(v);
            i += 4;
        }
        else if(s[i] == ',') i++;
        else if(s[i] == '?'){
            int v = ++n;
            if(!path.empty()){
                int u = path.back();
                adj[u].pb(v);
                adj[v].pb(u);
            }
            i++; k++;
        }
        else{
            path.pop_back(); i++;
        }
    }

    dfs(1);

    cout << max(0, k - L[1] - R[1]);

}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 51804 KB Output is correct
2 Correct 11 ms 51940 KB Output is correct
3 Correct 12 ms 50020 KB Output is correct
4 Correct 10 ms 51932 KB Output is correct
5 Correct 11 ms 51948 KB Output is correct
6 Correct 11 ms 51804 KB Output is correct
7 Correct 10 ms 51928 KB Output is correct
8 Correct 11 ms 51804 KB Output is correct
9 Correct 11 ms 51804 KB Output is correct
10 Correct 11 ms 51856 KB Output is correct
11 Correct 11 ms 51804 KB Output is correct
12 Correct 11 ms 51804 KB Output is correct
13 Correct 11 ms 51800 KB Output is correct
14 Correct 10 ms 51940 KB Output is correct
15 Correct 11 ms 51804 KB Output is correct
16 Correct 11 ms 51804 KB Output is correct
17 Correct 11 ms 51804 KB Output is correct
18 Correct 11 ms 49820 KB Output is correct
19 Correct 11 ms 51944 KB Output is correct
20 Correct 11 ms 51804 KB Output is correct
21 Correct 11 ms 49756 KB Output is correct
22 Correct 11 ms 51804 KB Output is correct
23 Correct 11 ms 51804 KB Output is correct
24 Correct 11 ms 51800 KB Output is correct
25 Correct 11 ms 51804 KB Output is correct
26 Correct 10 ms 49756 KB Output is correct
27 Correct 11 ms 51932 KB Output is correct
28 Correct 11 ms 51804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 51804 KB Output is correct
2 Correct 11 ms 51940 KB Output is correct
3 Correct 12 ms 50020 KB Output is correct
4 Correct 10 ms 51932 KB Output is correct
5 Correct 11 ms 51948 KB Output is correct
6 Correct 11 ms 51804 KB Output is correct
7 Correct 10 ms 51928 KB Output is correct
8 Correct 11 ms 51804 KB Output is correct
9 Correct 11 ms 51804 KB Output is correct
10 Correct 11 ms 51856 KB Output is correct
11 Correct 11 ms 51804 KB Output is correct
12 Correct 11 ms 51804 KB Output is correct
13 Correct 11 ms 51800 KB Output is correct
14 Correct 10 ms 51940 KB Output is correct
15 Correct 11 ms 51804 KB Output is correct
16 Correct 11 ms 51804 KB Output is correct
17 Correct 11 ms 51804 KB Output is correct
18 Correct 11 ms 49820 KB Output is correct
19 Correct 11 ms 51944 KB Output is correct
20 Correct 11 ms 51804 KB Output is correct
21 Correct 11 ms 49756 KB Output is correct
22 Correct 11 ms 51804 KB Output is correct
23 Correct 11 ms 51804 KB Output is correct
24 Correct 11 ms 51800 KB Output is correct
25 Correct 11 ms 51804 KB Output is correct
26 Correct 10 ms 49756 KB Output is correct
27 Correct 11 ms 51932 KB Output is correct
28 Correct 11 ms 51804 KB Output is correct
29 Correct 11 ms 51804 KB Output is correct
30 Correct 10 ms 51804 KB Output is correct
31 Correct 11 ms 51900 KB Output is correct
32 Correct 11 ms 51804 KB Output is correct
33 Correct 10 ms 51804 KB Output is correct
34 Correct 11 ms 51836 KB Output is correct
35 Correct 11 ms 51944 KB Output is correct
36 Correct 11 ms 51804 KB Output is correct
37 Correct 11 ms 51804 KB Output is correct
38 Correct 11 ms 51804 KB Output is correct
39 Correct 10 ms 51804 KB Output is correct
40 Correct 11 ms 51800 KB Output is correct
41 Correct 12 ms 51936 KB Output is correct
42 Correct 11 ms 51804 KB Output is correct
43 Correct 11 ms 51800 KB Output is correct
44 Correct 11 ms 51804 KB Output is correct
45 Correct 11 ms 51912 KB Output is correct
46 Correct 10 ms 51804 KB Output is correct
47 Correct 11 ms 51804 KB Output is correct
48 Correct 11 ms 51800 KB Output is correct
49 Correct 10 ms 49896 KB Output is correct
50 Correct 11 ms 51900 KB Output is correct
51 Correct 10 ms 51800 KB Output is correct
52 Correct 10 ms 51804 KB Output is correct
53 Correct 11 ms 51804 KB Output is correct
54 Correct 11 ms 49756 KB Output is correct
55 Correct 10 ms 52056 KB Output is correct
56 Correct 11 ms 51804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 369 ms 285648 KB Output is correct
2 Correct 346 ms 291600 KB Output is correct
3 Correct 344 ms 292196 KB Output is correct
4 Correct 350 ms 292816 KB Output is correct
5 Correct 334 ms 291436 KB Output is correct
6 Correct 338 ms 291504 KB Output is correct
7 Correct 338 ms 291536 KB Output is correct
8 Correct 341 ms 291848 KB Output is correct
9 Correct 336 ms 291784 KB Output is correct
10 Correct 340 ms 291636 KB Output is correct
11 Correct 341 ms 292176 KB Output is correct
12 Correct 335 ms 291888 KB Output is correct
13 Correct 11 ms 51804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 51804 KB Output is correct
2 Correct 11 ms 51940 KB Output is correct
3 Correct 12 ms 50020 KB Output is correct
4 Correct 10 ms 51932 KB Output is correct
5 Correct 11 ms 51948 KB Output is correct
6 Correct 11 ms 51804 KB Output is correct
7 Correct 10 ms 51928 KB Output is correct
8 Correct 11 ms 51804 KB Output is correct
9 Correct 11 ms 51804 KB Output is correct
10 Correct 11 ms 51856 KB Output is correct
11 Correct 11 ms 51804 KB Output is correct
12 Correct 11 ms 51804 KB Output is correct
13 Correct 11 ms 51800 KB Output is correct
14 Correct 10 ms 51940 KB Output is correct
15 Correct 11 ms 51804 KB Output is correct
16 Correct 11 ms 51804 KB Output is correct
17 Correct 11 ms 51804 KB Output is correct
18 Correct 11 ms 49820 KB Output is correct
19 Correct 11 ms 51944 KB Output is correct
20 Correct 11 ms 51804 KB Output is correct
21 Correct 11 ms 49756 KB Output is correct
22 Correct 11 ms 51804 KB Output is correct
23 Correct 11 ms 51804 KB Output is correct
24 Correct 11 ms 51800 KB Output is correct
25 Correct 11 ms 51804 KB Output is correct
26 Correct 10 ms 49756 KB Output is correct
27 Correct 11 ms 51932 KB Output is correct
28 Correct 11 ms 51804 KB Output is correct
29 Correct 11 ms 51804 KB Output is correct
30 Correct 10 ms 51804 KB Output is correct
31 Correct 11 ms 51900 KB Output is correct
32 Correct 11 ms 51804 KB Output is correct
33 Correct 10 ms 51804 KB Output is correct
34 Correct 11 ms 51836 KB Output is correct
35 Correct 11 ms 51944 KB Output is correct
36 Correct 11 ms 51804 KB Output is correct
37 Correct 11 ms 51804 KB Output is correct
38 Correct 11 ms 51804 KB Output is correct
39 Correct 10 ms 51804 KB Output is correct
40 Correct 11 ms 51800 KB Output is correct
41 Correct 12 ms 51936 KB Output is correct
42 Correct 11 ms 51804 KB Output is correct
43 Correct 11 ms 51800 KB Output is correct
44 Correct 11 ms 51804 KB Output is correct
45 Correct 11 ms 51912 KB Output is correct
46 Correct 10 ms 51804 KB Output is correct
47 Correct 11 ms 51804 KB Output is correct
48 Correct 11 ms 51800 KB Output is correct
49 Correct 10 ms 49896 KB Output is correct
50 Correct 11 ms 51900 KB Output is correct
51 Correct 10 ms 51800 KB Output is correct
52 Correct 10 ms 51804 KB Output is correct
53 Correct 11 ms 51804 KB Output is correct
54 Correct 11 ms 49756 KB Output is correct
55 Correct 10 ms 52056 KB Output is correct
56 Correct 11 ms 51804 KB Output is correct
57 Correct 11 ms 51800 KB Output is correct
58 Correct 11 ms 51804 KB Output is correct
59 Correct 11 ms 51804 KB Output is correct
60 Correct 11 ms 52016 KB Output is correct
61 Correct 11 ms 51804 KB Output is correct
62 Correct 11 ms 52060 KB Output is correct
63 Correct 12 ms 52060 KB Output is correct
64 Correct 11 ms 51876 KB Output is correct
65 Correct 12 ms 52004 KB Output is correct
66 Correct 11 ms 52060 KB Output is correct
67 Correct 11 ms 51800 KB Output is correct
68 Correct 11 ms 51800 KB Output is correct
69 Correct 12 ms 51848 KB Output is correct
70 Correct 11 ms 52024 KB Output is correct
71 Correct 11 ms 52020 KB Output is correct
72 Correct 11 ms 52060 KB Output is correct
73 Correct 11 ms 52060 KB Output is correct
74 Correct 11 ms 52060 KB Output is correct
75 Correct 11 ms 52060 KB Output is correct
76 Correct 11 ms 51940 KB Output is correct
77 Correct 11 ms 49756 KB Output is correct
78 Correct 11 ms 52028 KB Output is correct
79 Correct 11 ms 51804 KB Output is correct
80 Correct 11 ms 51804 KB Output is correct
81 Correct 11 ms 51940 KB Output is correct
82 Correct 11 ms 51876 KB Output is correct
83 Correct 11 ms 51804 KB Output is correct
84 Correct 11 ms 51804 KB Output is correct
85 Correct 11 ms 51864 KB Output is correct
86 Correct 11 ms 51892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 51804 KB Output is correct
2 Correct 11 ms 51940 KB Output is correct
3 Correct 12 ms 50020 KB Output is correct
4 Correct 10 ms 51932 KB Output is correct
5 Correct 11 ms 51948 KB Output is correct
6 Correct 11 ms 51804 KB Output is correct
7 Correct 10 ms 51928 KB Output is correct
8 Correct 11 ms 51804 KB Output is correct
9 Correct 11 ms 51804 KB Output is correct
10 Correct 11 ms 51856 KB Output is correct
11 Correct 11 ms 51804 KB Output is correct
12 Correct 11 ms 51804 KB Output is correct
13 Correct 11 ms 51800 KB Output is correct
14 Correct 10 ms 51940 KB Output is correct
15 Correct 11 ms 51804 KB Output is correct
16 Correct 11 ms 51804 KB Output is correct
17 Correct 11 ms 51804 KB Output is correct
18 Correct 11 ms 49820 KB Output is correct
19 Correct 11 ms 51944 KB Output is correct
20 Correct 11 ms 51804 KB Output is correct
21 Correct 11 ms 49756 KB Output is correct
22 Correct 11 ms 51804 KB Output is correct
23 Correct 11 ms 51804 KB Output is correct
24 Correct 11 ms 51800 KB Output is correct
25 Correct 11 ms 51804 KB Output is correct
26 Correct 10 ms 49756 KB Output is correct
27 Correct 11 ms 51932 KB Output is correct
28 Correct 11 ms 51804 KB Output is correct
29 Correct 11 ms 51804 KB Output is correct
30 Correct 10 ms 51804 KB Output is correct
31 Correct 11 ms 51900 KB Output is correct
32 Correct 11 ms 51804 KB Output is correct
33 Correct 10 ms 51804 KB Output is correct
34 Correct 11 ms 51836 KB Output is correct
35 Correct 11 ms 51944 KB Output is correct
36 Correct 11 ms 51804 KB Output is correct
37 Correct 11 ms 51804 KB Output is correct
38 Correct 11 ms 51804 KB Output is correct
39 Correct 10 ms 51804 KB Output is correct
40 Correct 11 ms 51800 KB Output is correct
41 Correct 12 ms 51936 KB Output is correct
42 Correct 11 ms 51804 KB Output is correct
43 Correct 11 ms 51800 KB Output is correct
44 Correct 11 ms 51804 KB Output is correct
45 Correct 11 ms 51912 KB Output is correct
46 Correct 10 ms 51804 KB Output is correct
47 Correct 11 ms 51804 KB Output is correct
48 Correct 11 ms 51800 KB Output is correct
49 Correct 10 ms 49896 KB Output is correct
50 Correct 11 ms 51900 KB Output is correct
51 Correct 10 ms 51800 KB Output is correct
52 Correct 10 ms 51804 KB Output is correct
53 Correct 11 ms 51804 KB Output is correct
54 Correct 11 ms 49756 KB Output is correct
55 Correct 10 ms 52056 KB Output is correct
56 Correct 11 ms 51804 KB Output is correct
57 Correct 369 ms 285648 KB Output is correct
58 Correct 346 ms 291600 KB Output is correct
59 Correct 344 ms 292196 KB Output is correct
60 Correct 350 ms 292816 KB Output is correct
61 Correct 334 ms 291436 KB Output is correct
62 Correct 338 ms 291504 KB Output is correct
63 Correct 338 ms 291536 KB Output is correct
64 Correct 341 ms 291848 KB Output is correct
65 Correct 336 ms 291784 KB Output is correct
66 Correct 340 ms 291636 KB Output is correct
67 Correct 341 ms 292176 KB Output is correct
68 Correct 335 ms 291888 KB Output is correct
69 Correct 11 ms 51804 KB Output is correct
70 Correct 11 ms 51800 KB Output is correct
71 Correct 11 ms 51804 KB Output is correct
72 Correct 11 ms 51804 KB Output is correct
73 Correct 11 ms 52016 KB Output is correct
74 Correct 11 ms 51804 KB Output is correct
75 Correct 11 ms 52060 KB Output is correct
76 Correct 12 ms 52060 KB Output is correct
77 Correct 11 ms 51876 KB Output is correct
78 Correct 12 ms 52004 KB Output is correct
79 Correct 11 ms 52060 KB Output is correct
80 Correct 11 ms 51800 KB Output is correct
81 Correct 11 ms 51800 KB Output is correct
82 Correct 12 ms 51848 KB Output is correct
83 Correct 11 ms 52024 KB Output is correct
84 Correct 11 ms 52020 KB Output is correct
85 Correct 11 ms 52060 KB Output is correct
86 Correct 11 ms 52060 KB Output is correct
87 Correct 11 ms 52060 KB Output is correct
88 Correct 11 ms 52060 KB Output is correct
89 Correct 11 ms 51940 KB Output is correct
90 Correct 11 ms 49756 KB Output is correct
91 Correct 11 ms 52028 KB Output is correct
92 Correct 11 ms 51804 KB Output is correct
93 Correct 11 ms 51804 KB Output is correct
94 Correct 11 ms 51940 KB Output is correct
95 Correct 11 ms 51876 KB Output is correct
96 Correct 11 ms 51804 KB Output is correct
97 Correct 11 ms 51804 KB Output is correct
98 Correct 11 ms 51864 KB Output is correct
99 Correct 11 ms 51892 KB Output is correct
100 Correct 270 ms 147176 KB Output is correct
101 Correct 273 ms 147140 KB Output is correct
102 Correct 275 ms 147528 KB Output is correct
103 Correct 259 ms 148256 KB Output is correct
104 Correct 258 ms 147152 KB Output is correct
105 Correct 310 ms 196468 KB Output is correct
106 Correct 303 ms 195536 KB Output is correct
107 Correct 304 ms 195964 KB Output is correct
108 Correct 301 ms 195280 KB Output is correct
109 Correct 309 ms 195372 KB Output is correct
110 Correct 271 ms 147148 KB Output is correct
111 Correct 279 ms 147664 KB Output is correct
112 Correct 262 ms 147536 KB Output is correct
113 Correct 270 ms 147808 KB Output is correct
114 Correct 264 ms 147016 KB Output is correct
115 Correct 349 ms 291520 KB Output is correct
116 Correct 349 ms 291292 KB Output is correct
117 Correct 342 ms 292560 KB Output is correct
118 Correct 352 ms 292064 KB Output is correct
119 Correct 346 ms 292304 KB Output is correct
120 Correct 268 ms 140500 KB Output is correct
121 Correct 264 ms 148132 KB Output is correct
122 Correct 266 ms 148524 KB Output is correct
123 Correct 263 ms 147264 KB Output is correct
124 Correct 300 ms 227652 KB Output is correct
125 Correct 290 ms 225904 KB Output is correct
126 Correct 293 ms 228636 KB Output is correct
127 Correct 290 ms 224840 KB Output is correct
128 Correct 156 ms 104148 KB Output is correct
129 Correct 148 ms 104228 KB Output is correct
130 Correct 141 ms 104148 KB Output is correct
131 Correct 11 ms 51804 KB Output is correct