답안 #1054996

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054996 2024-08-12T13:46:17 Z gagik_2007 Homework (CEOI22_homework) C++17
100 / 100
142 ms 171860 KB
#include <bits/stdc++.h>
using namespace std;

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

#define ff first
#define ss second

ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=2000007;
ll n,m,k;
int tp[N];
int l[N],r[N];
int x[N],y[N];
int sz[N];
int cur=1;
int ind=0;
vector<int>g[N];
string s;

int parse(){
    int v=cur;
    cur++;
    char c=s[ind];
    ind++;
    if(c=='?'){
        tp[v]=0;
        return v;
    }
    c=s[ind];
    ind+=3;
    if(c=='i'){
        tp[v]=1;
    }
    else{
        tp[v]=2;
    }
    int lft=parse();
    ind++;
    int rgh=parse();
    l[v]=lft;
    r[v]=rgh;
    ind++;
    return v;
}

void recurs(int v){
    if(tp[v]==0){
        x[v]=y[v]=1;
        sz[v]=1;
        return;
    }
    recurs(l[v]);
    recurs(r[v]);
    sz[v]=sz[l[v]]+sz[r[v]];
    if(tp[v]==1){
        x[v]=min(x[l[v]],x[r[v]]);
        y[v]=y[l[v]]+y[r[v]]-1;
    }
    else{
        x[v]=x[l[v]]+x[r[v]];
        y[v]=max(y[l[v]]+sz[r[v]],y[r[v]]+sz[l[v]]);
    }
    // cout<<v<<": "<<x[v]<<" "<<y[v]<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // freopen("Binput.txt","r",stdin);
    // freopen("Boutput.txt","w",stdout);
    cin>>s;
    int root=parse();
    recurs(root);
    cout<<y[root]-x[root]+1<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 47448 KB Output is correct
2 Correct 16 ms 47452 KB Output is correct
3 Correct 16 ms 47452 KB Output is correct
4 Correct 16 ms 47452 KB Output is correct
5 Correct 18 ms 47352 KB Output is correct
6 Correct 16 ms 47452 KB Output is correct
7 Correct 16 ms 47452 KB Output is correct
8 Correct 19 ms 47420 KB Output is correct
9 Correct 26 ms 47452 KB Output is correct
10 Correct 16 ms 47452 KB Output is correct
11 Correct 18 ms 47428 KB Output is correct
12 Correct 16 ms 47404 KB Output is correct
13 Correct 8 ms 57944 KB Output is correct
14 Correct 8 ms 57944 KB Output is correct
15 Correct 7 ms 57948 KB Output is correct
16 Correct 10 ms 57948 KB Output is correct
17 Correct 10 ms 47440 KB Output is correct
18 Correct 11 ms 47260 KB Output is correct
19 Correct 11 ms 47452 KB Output is correct
20 Correct 9 ms 47436 KB Output is correct
21 Correct 11 ms 47452 KB Output is correct
22 Correct 13 ms 47452 KB Output is correct
23 Correct 8 ms 47448 KB Output is correct
24 Correct 8 ms 47452 KB Output is correct
25 Correct 12 ms 47452 KB Output is correct
26 Correct 9 ms 47452 KB Output is correct
27 Correct 9 ms 47452 KB Output is correct
28 Correct 11 ms 47296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 47448 KB Output is correct
2 Correct 16 ms 47452 KB Output is correct
3 Correct 16 ms 47452 KB Output is correct
4 Correct 16 ms 47452 KB Output is correct
5 Correct 18 ms 47352 KB Output is correct
6 Correct 16 ms 47452 KB Output is correct
7 Correct 16 ms 47452 KB Output is correct
8 Correct 19 ms 47420 KB Output is correct
9 Correct 26 ms 47452 KB Output is correct
10 Correct 16 ms 47452 KB Output is correct
11 Correct 18 ms 47428 KB Output is correct
12 Correct 16 ms 47404 KB Output is correct
13 Correct 8 ms 57944 KB Output is correct
14 Correct 8 ms 57944 KB Output is correct
15 Correct 7 ms 57948 KB Output is correct
16 Correct 10 ms 57948 KB Output is correct
17 Correct 10 ms 47440 KB Output is correct
18 Correct 11 ms 47260 KB Output is correct
19 Correct 11 ms 47452 KB Output is correct
20 Correct 9 ms 47436 KB Output is correct
21 Correct 11 ms 47452 KB Output is correct
22 Correct 13 ms 47452 KB Output is correct
23 Correct 8 ms 47448 KB Output is correct
24 Correct 8 ms 47452 KB Output is correct
25 Correct 12 ms 47452 KB Output is correct
26 Correct 9 ms 47452 KB Output is correct
27 Correct 9 ms 47452 KB Output is correct
28 Correct 11 ms 47296 KB Output is correct
29 Correct 8 ms 47248 KB Output is correct
30 Correct 9 ms 47452 KB Output is correct
31 Correct 9 ms 47452 KB Output is correct
32 Correct 10 ms 47436 KB Output is correct
33 Correct 11 ms 47460 KB Output is correct
34 Correct 9 ms 47452 KB Output is correct
35 Correct 10 ms 47452 KB Output is correct
36 Correct 11 ms 47452 KB Output is correct
37 Correct 10 ms 47448 KB Output is correct
38 Correct 8 ms 47452 KB Output is correct
39 Correct 11 ms 47272 KB Output is correct
40 Correct 9 ms 47452 KB Output is correct
41 Correct 9 ms 47448 KB Output is correct
42 Correct 10 ms 47452 KB Output is correct
43 Correct 16 ms 47448 KB Output is correct
44 Correct 17 ms 47452 KB Output is correct
45 Correct 16 ms 47448 KB Output is correct
46 Correct 16 ms 47444 KB Output is correct
47 Correct 24 ms 47444 KB Output is correct
48 Correct 23 ms 47352 KB Output is correct
49 Correct 15 ms 47448 KB Output is correct
50 Correct 21 ms 47448 KB Output is correct
51 Correct 16 ms 47452 KB Output is correct
52 Correct 17 ms 47256 KB Output is correct
53 Correct 17 ms 47452 KB Output is correct
54 Correct 22 ms 47448 KB Output is correct
55 Correct 16 ms 47452 KB Output is correct
56 Correct 20 ms 47452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 170712 KB Output is correct
2 Correct 92 ms 166876 KB Output is correct
3 Correct 96 ms 168656 KB Output is correct
4 Correct 94 ms 166796 KB Output is correct
5 Correct 99 ms 166864 KB Output is correct
6 Correct 104 ms 166984 KB Output is correct
7 Correct 113 ms 167888 KB Output is correct
8 Correct 125 ms 167800 KB Output is correct
9 Correct 142 ms 166952 KB Output is correct
10 Correct 102 ms 166880 KB Output is correct
11 Correct 88 ms 171464 KB Output is correct
12 Correct 117 ms 166900 KB Output is correct
13 Correct 7 ms 47704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 47448 KB Output is correct
2 Correct 16 ms 47452 KB Output is correct
3 Correct 16 ms 47452 KB Output is correct
4 Correct 16 ms 47452 KB Output is correct
5 Correct 18 ms 47352 KB Output is correct
6 Correct 16 ms 47452 KB Output is correct
7 Correct 16 ms 47452 KB Output is correct
8 Correct 19 ms 47420 KB Output is correct
9 Correct 26 ms 47452 KB Output is correct
10 Correct 16 ms 47452 KB Output is correct
11 Correct 18 ms 47428 KB Output is correct
12 Correct 16 ms 47404 KB Output is correct
13 Correct 8 ms 57944 KB Output is correct
14 Correct 8 ms 57944 KB Output is correct
15 Correct 7 ms 57948 KB Output is correct
16 Correct 10 ms 57948 KB Output is correct
17 Correct 10 ms 47440 KB Output is correct
18 Correct 11 ms 47260 KB Output is correct
19 Correct 11 ms 47452 KB Output is correct
20 Correct 9 ms 47436 KB Output is correct
21 Correct 11 ms 47452 KB Output is correct
22 Correct 13 ms 47452 KB Output is correct
23 Correct 8 ms 47448 KB Output is correct
24 Correct 8 ms 47452 KB Output is correct
25 Correct 12 ms 47452 KB Output is correct
26 Correct 9 ms 47452 KB Output is correct
27 Correct 9 ms 47452 KB Output is correct
28 Correct 11 ms 47296 KB Output is correct
29 Correct 8 ms 47248 KB Output is correct
30 Correct 9 ms 47452 KB Output is correct
31 Correct 9 ms 47452 KB Output is correct
32 Correct 10 ms 47436 KB Output is correct
33 Correct 11 ms 47460 KB Output is correct
34 Correct 9 ms 47452 KB Output is correct
35 Correct 10 ms 47452 KB Output is correct
36 Correct 11 ms 47452 KB Output is correct
37 Correct 10 ms 47448 KB Output is correct
38 Correct 8 ms 47452 KB Output is correct
39 Correct 11 ms 47272 KB Output is correct
40 Correct 9 ms 47452 KB Output is correct
41 Correct 9 ms 47448 KB Output is correct
42 Correct 10 ms 47452 KB Output is correct
43 Correct 16 ms 47448 KB Output is correct
44 Correct 17 ms 47452 KB Output is correct
45 Correct 16 ms 47448 KB Output is correct
46 Correct 16 ms 47444 KB Output is correct
47 Correct 24 ms 47444 KB Output is correct
48 Correct 23 ms 47352 KB Output is correct
49 Correct 15 ms 47448 KB Output is correct
50 Correct 21 ms 47448 KB Output is correct
51 Correct 16 ms 47452 KB Output is correct
52 Correct 17 ms 47256 KB Output is correct
53 Correct 17 ms 47452 KB Output is correct
54 Correct 22 ms 47448 KB Output is correct
55 Correct 16 ms 47452 KB Output is correct
56 Correct 20 ms 47452 KB Output is correct
57 Correct 8 ms 49756 KB Output is correct
58 Correct 7 ms 47708 KB Output is correct
59 Correct 10 ms 47708 KB Output is correct
60 Correct 8 ms 57948 KB Output is correct
61 Correct 9 ms 57988 KB Output is correct
62 Correct 8 ms 57944 KB Output is correct
63 Correct 9 ms 57948 KB Output is correct
64 Correct 19 ms 47452 KB Output is correct
65 Correct 20 ms 47452 KB Output is correct
66 Correct 18 ms 47452 KB Output is correct
67 Correct 18 ms 47396 KB Output is correct
68 Correct 24 ms 47452 KB Output is correct
69 Correct 19 ms 47464 KB Output is correct
70 Correct 18 ms 47452 KB Output is correct
71 Correct 22 ms 47452 KB Output is correct
72 Correct 18 ms 47560 KB Output is correct
73 Correct 18 ms 47452 KB Output is correct
74 Correct 17 ms 47452 KB Output is correct
75 Correct 17 ms 47492 KB Output is correct
76 Correct 23 ms 47448 KB Output is correct
77 Correct 17 ms 47448 KB Output is correct
78 Correct 16 ms 47452 KB Output is correct
79 Correct 15 ms 47452 KB Output is correct
80 Correct 22 ms 47452 KB Output is correct
81 Correct 16 ms 47452 KB Output is correct
82 Correct 15 ms 47452 KB Output is correct
83 Correct 16 ms 47452 KB Output is correct
84 Correct 17 ms 47484 KB Output is correct
85 Correct 7 ms 49756 KB Output is correct
86 Correct 8 ms 49816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 47448 KB Output is correct
2 Correct 16 ms 47452 KB Output is correct
3 Correct 16 ms 47452 KB Output is correct
4 Correct 16 ms 47452 KB Output is correct
5 Correct 18 ms 47352 KB Output is correct
6 Correct 16 ms 47452 KB Output is correct
7 Correct 16 ms 47452 KB Output is correct
8 Correct 19 ms 47420 KB Output is correct
9 Correct 26 ms 47452 KB Output is correct
10 Correct 16 ms 47452 KB Output is correct
11 Correct 18 ms 47428 KB Output is correct
12 Correct 16 ms 47404 KB Output is correct
13 Correct 8 ms 57944 KB Output is correct
14 Correct 8 ms 57944 KB Output is correct
15 Correct 7 ms 57948 KB Output is correct
16 Correct 10 ms 57948 KB Output is correct
17 Correct 10 ms 47440 KB Output is correct
18 Correct 11 ms 47260 KB Output is correct
19 Correct 11 ms 47452 KB Output is correct
20 Correct 9 ms 47436 KB Output is correct
21 Correct 11 ms 47452 KB Output is correct
22 Correct 13 ms 47452 KB Output is correct
23 Correct 8 ms 47448 KB Output is correct
24 Correct 8 ms 47452 KB Output is correct
25 Correct 12 ms 47452 KB Output is correct
26 Correct 9 ms 47452 KB Output is correct
27 Correct 9 ms 47452 KB Output is correct
28 Correct 11 ms 47296 KB Output is correct
29 Correct 8 ms 47248 KB Output is correct
30 Correct 9 ms 47452 KB Output is correct
31 Correct 9 ms 47452 KB Output is correct
32 Correct 10 ms 47436 KB Output is correct
33 Correct 11 ms 47460 KB Output is correct
34 Correct 9 ms 47452 KB Output is correct
35 Correct 10 ms 47452 KB Output is correct
36 Correct 11 ms 47452 KB Output is correct
37 Correct 10 ms 47448 KB Output is correct
38 Correct 8 ms 47452 KB Output is correct
39 Correct 11 ms 47272 KB Output is correct
40 Correct 9 ms 47452 KB Output is correct
41 Correct 9 ms 47448 KB Output is correct
42 Correct 10 ms 47452 KB Output is correct
43 Correct 16 ms 47448 KB Output is correct
44 Correct 17 ms 47452 KB Output is correct
45 Correct 16 ms 47448 KB Output is correct
46 Correct 16 ms 47444 KB Output is correct
47 Correct 24 ms 47444 KB Output is correct
48 Correct 23 ms 47352 KB Output is correct
49 Correct 15 ms 47448 KB Output is correct
50 Correct 21 ms 47448 KB Output is correct
51 Correct 16 ms 47452 KB Output is correct
52 Correct 17 ms 47256 KB Output is correct
53 Correct 17 ms 47452 KB Output is correct
54 Correct 22 ms 47448 KB Output is correct
55 Correct 16 ms 47452 KB Output is correct
56 Correct 20 ms 47452 KB Output is correct
57 Correct 83 ms 170712 KB Output is correct
58 Correct 92 ms 166876 KB Output is correct
59 Correct 96 ms 168656 KB Output is correct
60 Correct 94 ms 166796 KB Output is correct
61 Correct 99 ms 166864 KB Output is correct
62 Correct 104 ms 166984 KB Output is correct
63 Correct 113 ms 167888 KB Output is correct
64 Correct 125 ms 167800 KB Output is correct
65 Correct 142 ms 166952 KB Output is correct
66 Correct 102 ms 166880 KB Output is correct
67 Correct 88 ms 171464 KB Output is correct
68 Correct 117 ms 166900 KB Output is correct
69 Correct 7 ms 47704 KB Output is correct
70 Correct 8 ms 49756 KB Output is correct
71 Correct 7 ms 47708 KB Output is correct
72 Correct 10 ms 47708 KB Output is correct
73 Correct 8 ms 57948 KB Output is correct
74 Correct 9 ms 57988 KB Output is correct
75 Correct 8 ms 57944 KB Output is correct
76 Correct 9 ms 57948 KB Output is correct
77 Correct 19 ms 47452 KB Output is correct
78 Correct 20 ms 47452 KB Output is correct
79 Correct 18 ms 47452 KB Output is correct
80 Correct 18 ms 47396 KB Output is correct
81 Correct 24 ms 47452 KB Output is correct
82 Correct 19 ms 47464 KB Output is correct
83 Correct 18 ms 47452 KB Output is correct
84 Correct 22 ms 47452 KB Output is correct
85 Correct 18 ms 47560 KB Output is correct
86 Correct 18 ms 47452 KB Output is correct
87 Correct 17 ms 47452 KB Output is correct
88 Correct 17 ms 47492 KB Output is correct
89 Correct 23 ms 47448 KB Output is correct
90 Correct 17 ms 47448 KB Output is correct
91 Correct 16 ms 47452 KB Output is correct
92 Correct 15 ms 47452 KB Output is correct
93 Correct 22 ms 47452 KB Output is correct
94 Correct 16 ms 47452 KB Output is correct
95 Correct 15 ms 47452 KB Output is correct
96 Correct 16 ms 47452 KB Output is correct
97 Correct 17 ms 47484 KB Output is correct
98 Correct 7 ms 49756 KB Output is correct
99 Correct 8 ms 49816 KB Output is correct
100 Correct 75 ms 107948 KB Output is correct
101 Correct 47 ms 109400 KB Output is correct
102 Correct 53 ms 107988 KB Output is correct
103 Correct 57 ms 108616 KB Output is correct
104 Correct 50 ms 108764 KB Output is correct
105 Correct 72 ms 129604 KB Output is correct
106 Correct 73 ms 129492 KB Output is correct
107 Correct 82 ms 128828 KB Output is correct
108 Correct 75 ms 128972 KB Output is correct
109 Correct 82 ms 128940 KB Output is correct
110 Correct 66 ms 107976 KB Output is correct
111 Correct 68 ms 108100 KB Output is correct
112 Correct 46 ms 108164 KB Output is correct
113 Correct 51 ms 108348 KB Output is correct
114 Correct 72 ms 108132 KB Output is correct
115 Correct 128 ms 166808 KB Output is correct
116 Correct 108 ms 166824 KB Output is correct
117 Correct 116 ms 166828 KB Output is correct
118 Correct 114 ms 166716 KB Output is correct
119 Correct 104 ms 171860 KB Output is correct
120 Correct 62 ms 108104 KB Output is correct
121 Correct 58 ms 108092 KB Output is correct
122 Correct 59 ms 107980 KB Output is correct
123 Correct 61 ms 107960 KB Output is correct
124 Correct 77 ms 139416 KB Output is correct
125 Correct 95 ms 139468 KB Output is correct
126 Correct 77 ms 139412 KB Output is correct
127 Correct 67 ms 139708 KB Output is correct
128 Correct 33 ms 79272 KB Output is correct
129 Correct 35 ms 79372 KB Output is correct
130 Correct 43 ms 79324 KB Output is correct
131 Correct 13 ms 47452 KB Output is correct