QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#141667 | #6742. Leaves | 275307894a | WA | 1ms | 3836kb | C++14 | 1.2kb | 2023-08-17 20:12:00 | 2023-08-17 20:12:01 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=1e3+5,M=2e3+5,K=63,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
int n,m,l[N],r[N],A[N];
#define vb vector<basic_string<int> >
vb dfs(int x){
// cerr<<x<<'\n';
if(!l[x])return {{A[x]}};
vb f1=dfs(l[x]),f2=dfs(r[x]),f(f1.size()+f2.size());
for(int i=0;i<f1.size();i++){
for(int j=0;j<f2.size();j++){
if(f[i+j].empty()) f[i+j]=f1[i]+f2[j];
else f[i+j]=min(f[i+j],f1[i]+f2[j]);
if(f[i+j+1].empty()) f[i+j+1]=f2[j]+f1[i];
else f[i+j+1]=min(f[i+j+1],f2[j]+f1[i]);
}
}
return f;
}
int main(){
int i,j;scanf("%d%d",&n,&m);
for(i=1;i<=n;i++) {
int op;scanf("%d",&op);
if(op==1) scanf("%d%d",&l[i],&r[i]);
else scanf("%d",&A[i]);
}
auto p=dfs(1)[m];
for(int i:p) printf("%d ",i);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3780kb
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: 1ms
memory: 3776kb
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: 1ms
memory: 3836kb
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: 3828kb
input:
1 0 2 1000000000
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3796kb
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: 1ms
memory: 3792kb
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'