# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1124147 | EfeBabagil | Homework (CEOI22_homework) | C++20 | 1100 ms | 109140 KiB |
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
string s;
int cur;
vector<int> v;
struct tree
{
char node;
tree* left;
tree* right;
};
tree* parse()
{
if(s[cur] == '?')
{
cur++;
return new tree{'?',nullptr,nullptr};
}
tree* l;
tree* r;
char n;
n=s[cur+1];
cur+=4;
l = parse();
cur++;
r = parse();
cur++;
return new tree{n,l,r};
}
int dfs(tree* x)
{
if(x->node=='?')
{
return v[cur++];
}
if(x->node=='i')
{
return min(dfs(x->left),dfs(x->right));
}
if(x->node=='a')
{
return max(dfs(x->left),dfs(x->right));
}
}
int main()
{
cin>>s;
int n=(s.size()+6)/7;
auto root=parse();
vector<bool> ans(n+1);
for(int i=0;i<n;i++)
v.push_back(i+1);
vector<int> temp=v;
do
{
cur=0;
ans[dfs(root)]=1;
}while (next_permutation(v.begin(), v.end()));
int tot=0;
for(int i=1;i<n+1;i++)
{
if(ans[i]==1)
tot++;
}
cout<<tot;
return 0;
}
Compilation message (stderr)
# | 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... |