이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
const int N = 1e6;
string s;
int n;
vector<int> to[N];
pair<int, int> buildtree(int l, int r, int d){
if(l==r)return {1, n};
pair<int, int> ans1;
pair<int, int> ans2;
int pos = to[d].back();
to[d].pop_back();
ans1 = buildtree(l+4, pos-1, d+1);
ans2 = buildtree(pos+1, r-1, d+1);
if(s[l+2]=='x'){
pair<int, int> ret;
ret.S = max(ans1.S, ans2.S);
ret.F = max(ans1.F, ans2.F);
if(ans1.F==ans2.F)ret.F++;
return ret;
}
else{
pair<int, int> ret;
ret.S = min(ans1.S, ans2.S);
ret.F = min(ans1.F, ans2.F);
if(ans1.S==ans2.S)ret.S--;
return ret;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> s;
int cnto=0;
for(int i=0; i< s.size(); i++){
char c = s[i];
if(c=='?')n++;
if(c=='(')cnto++;
if(c==')')cnto--;
if(c==',')to[cnto-1].push_back(i);
}
for(int i=0; i<10; i++){
reverse(to[i].begin(), to[i].end());
}
pair<int, int> ans = buildtree(0, s.size()-1, 0);
cout << ans.S-ans.F << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:44:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i=0; i< s.size(); i++){
| ~^~~~~~~~~~
# | 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... |