QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#637818#6742. LeavesUESTC_DECAYALI#WA 1ms4128kbC++201.3kb2024-10-13 14:10:482024-10-13 14:10:50

Judging History

你现在查看的是最新测评结果

  • [2024-10-13 14:10:50]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4128kb
  • [2024-10-13 14:10:48]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<vector>
#define RI register int
#define CI const int&
using namespace std;
const int N=1005,INF=1e9+5;
int n,m,tp,l[N],r[N],a[N],sz[N]; vector <int> f[N][N/2];
inline void DFS(CI now=1)
{
    if (a[now])
    {
        f[now][0]={a[now]}; f[now][1]={INF};
        return;
    }
    int ls=l[now],rs=r[now]; sz[now]=1;
    DFS(ls); DFS(rs); sz[now]+=sz[ls]+sz[rs];
    for (RI i=0;i<=min(m,sz[now]);++i) f[now][i]={INF};
    auto merge=[&](vector <int>& A,vector <int>& B)
    {
        vector <int> vec=A;
        for (auto& x:B) vec.push_back(x);
        return vec;
    };
    for (RI p=0;p<=min(m,sz[ls]);++p)
    for (RI q=0;q<=min(m-q,sz[rs]);++q)
    {
        f[now][p+q]=min(f[now][p+q],merge(f[ls][p],f[rs][q]));
        if (p+q+1<=m) f[now][p+q+1]=min(f[now][p+q+1],merge(f[rs][q],f[ls][p]));
    }
    for (RI i=0;i<=min(m,sz[ls]);++i) f[ls][i].shrink_to_fit();
    for (RI i=0;i<=min(m,sz[ls]);++i) f[rs][i].shrink_to_fit();
}
int main()
{
    scanf("%d%d",&n,&m);
    for (RI i=1;i<=n;++i)
    {
        scanf("%d",&tp);
        if (tp==1) scanf("%d%d",&l[i],&r[i]);
        else scanf("%d",&a[i]);
    }
    DFS(); vector <int> ans={INF};
    //for (RI i=m;i>=0;i-=2) ans=min(ans,f[1][i]);
	 ans=min(ans,f[1][m]);
    for (auto x:ans) printf("%d ",x);
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 4128kb

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: 3800kb

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: 3856kb

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: 3816kb

input:

1 0
2 1000000000

output:

1000000000 

result:

ok 1 number(s): "1000000000"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3812kb

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: 3888kb

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'