QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#183626 | #6742. Leaves | lengli | WA | 2ms | 6168kb | C++23 | 1.5kb | 2023-09-19 18:29:58 | 2023-09-19 18:29:58 |
Judging History
answer
/*
lengli_QAQ
Hope there are no bugs!!!
*/
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl '\n'
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
//--------------------------------
template<typename T> void printvt(vector<T> &a){
for(auto x:a) cout<<x<<" ";cout<<endl;
};
template<typename T> void printay(T a[],int l,int r){
for(int i=l;i<=r;i++) cout<<a[i]<<" ";cout<<endl;
};
//--------------------------------
typedef pair<int,int> PII;
typedef long long LL;
const int N=100010;
int n,m;
vector<int> eg[N];
int a[N];
vector<int> get(vector<int> l,vector<int> r){
vector<int> res=l;
for(auto x:r) res.pb(x);
return res;
}
vector<vector<int>> dfs(int u){
vector<vector<int>> res;
if(eg[u].empty()) res.pb({a[u]});
else{
auto l=dfs(eg[u][0]);
auto r=dfs(eg[u][1]);
res.resize(l.size()+r.size());
for(int i=0;i<l.size();i++){
for(int j=0;j<r.size();j++){
vector<int> t=get(l[i],r[j]);
if(res[i+j].size()==0 or res[i+j]>t) res[i+j]=t;
t=get(r[j],l[i]);
if(res[i+j+1].size()==0 or res[i+j+1]>t) res[i+j+1]=t;
}
}
}
return res;
}
void solve(){
cin>>n>>m;
for(int i=1;i<=n;i++){
int op;
cin>>op;
if(op==1) {
int l,r;
cin>>l>>r;
eg[i].pb(l);
eg[i].pb(r);
}else cin>>a[i];
}
auto res=dfs(1);
printvt(res[m]);
}
signed main(){
fastio;
int T;
T=1;
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5948kb
input:
3 0 1 2 3 2 1 2 2
output:
1 2
result:
ok 2 number(s): "1 2"
Test #2:
score: 0
Accepted
time: 2ms
memory: 5964kb
input:
7 1 1 2 3 1 4 5 1 6 7 2 4 2 2 2 3 2 1
output:
2 4 3 1
result:
ok 4 number(s): "2 4 3 1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 6168kb
input:
7 2 1 2 3 1 4 5 1 6 7 2 4 2 2 2 3 2 1
output:
1 3 4 2
result:
ok 4 number(s): "1 3 4 2"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5976kb
input:
1 0 2 1000000000
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #5:
score: 0
Accepted
time: 0ms
memory: 5880kb
input:
3 1 1 2 3 2 1 2 2
output:
2 1
result:
ok 2 number(s): "2 1"
Test #6:
score: -100
Wrong Answer
time: 2ms
memory: 5948kb
input:
7 2 1 2 3 1 4 5 1 6 7 2 1 2 2 2 3 2 4
output:
2 1 4 3
result:
wrong answer 1st numbers differ - expected: '1', found: '2'