이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
string str;
int bin[1000005][2];
int type[1000005], sz[1000005];
int cnode = 0;
stack<int> stk;
int ci = 0;
pair<int, int> dfs(int x) {
if(type[x] == 2) return {1, 1};
if(type[x] == 0) {
auto r1 = dfs(bin[x][0]), r2 = dfs(bin[x][1]);
return {min(r1.first, r2.first), sz[x]+1-(sz[bin[x][0]]+sz[bin[x][1]]-r1.second-r2.second+2)};
} else {
auto r1 = dfs(bin[x][0]), r2 = dfs(bin[x][1]);
return {r1.first + r2.first, sz[x]-min(sz[bin[x][0]]-r1.second, sz[bin[x][1]]-r2.second)};
}
}
int main() {
cin >> str;
for(int i=0;i<str.size();) {
if(str[i] == ',' || str[i]=='('){i++; continue;}
if(str[i] == 'm') {
stk.push(cnode);
if(str[i+1] == 'i') { //minimum
type[cnode++] = 0;
} else {
type[cnode++] = 1;
}
i += 4;
} else if(str[i] == '?') {
stk.push(cnode); sz[cnode] = 1;
type[cnode++] = 2;
i++;
} else {
int e1 = stk.top(); stk.pop();
int e2 = stk.top(); stk.pop();
bin[stk.top()][0] = e2; bin[stk.top()][1] = e1;
sz[stk.top()] = sz[e1] + sz[e2];
i++;
}
}
pair<int, int> res = dfs(0);
cout << res.second - res.first + 1;
}
// min(max(max(?,?),max(?,?)),min(max(?,?),max(?,?)))
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:26:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i=0;i<str.size();) {
| ~^~~~~~~~~~~
# | 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... |