이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e6;
string s;
int n;
int pos;
int type[MAX_N + 1], leftSon[MAX_N + 1], rightSon[MAX_N + 1], sz[MAX_N + 1], minn[MAX_N + 1], maxx[MAX_N + 1];
int buildTree() {
n++;
int v = n;
if ( s[pos] == '?' ) {
type[v] = 0;
return v;
}
type[v] = (s[pos + 1] == 'i' ? 1 : 2);
pos += 4;
leftSon[v] = buildTree();
pos += 2;
rightSon[v] = buildTree();
pos++;
return v;
}
void dfs( int v ) {
if ( type[v] == 0 ) {
minn[v] = maxx[v] = sz[v] = 1;
return;
}
int l = leftSon[v], r = rightSon[v];
dfs( l );
dfs( r );
if ( type[v] == 1 ) {
minn[v] = min( minn[l], minn[r] );
maxx[v] = maxx[l] + maxx[r] - 1;
} else {
minn[v] = minn[l] + minn[r];
maxx[v] = max( sz[l] + maxx[r], sz[r] + maxx[l] );
}
sz[v] = sz[l] + sz[r];
};
int main() {
cin >> s;
pos = 0;
buildTree();
dfs( 1 );
cout << maxx[1] - minn[1] + 1 << "\n";
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |