QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#165711#6742. Leavesmendicillin2WA 1ms3828kbC++143.0kb2023-09-05 21:06:482023-09-05 21:06:48

Judging History

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

  • [2023-09-05 21:06:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3828kb
  • [2023-09-05 21:06:48]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

inline int read()
{
	int x=0,f=1;
	char c=getchar();
	while(c<'0' || c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0' && c<='9')
	{
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}

const int N=1000+5;
int n,m;
int ch[N][2],a[N];
bitset<N> f[N][505];
int dp[N];

vector<int> re[N];
vector<int> s1,s2;

inline bool check()
{
    for(int i=0;i<(int)s1.size();i++)
    {
        if(s1[i]>s2[i]) return true;
        if(s1[i]<s2[i]) return false;
    }
    return false;
}

inline void dfs1(int x)
{
    if(!ch[x][0]) 
    {
        re[x].push_back(a[x]);
        return;
    }
    dfs1(ch[x][0]); dfs1(ch[x][1]);
    s1.clear();
    s2.clear();
    dp[x]=dp[ch[x][0]]+dp[ch[x][1]];
    for(int i=0;i<(int)re[ch[x][0]].size();i++) s1.push_back(re[ch[x][0]][i]);
    for(int i=0;i<(int)re[ch[x][1]].size();i++) s1.push_back(re[ch[x][1]][i]), s2.push_back(re[ch[x][1]][i]);
    for(int i=0;i<(int)re[ch[x][0]].size();i++) s2.push_back(re[ch[x][0]][i]);
    if(check()) 
    {
        dp[x]++;
        re[x]=s2;
    }
    else re[x]=s1;
}

inline void dfs3(int x,bitset<N> s,int flag)
{
    if(!ch[x][0])
    {
        if(flag==1) s1.push_back(a[x]);
        else s2.push_back(a[x]);
        return;
    }
    if(s[x]) dfs3(ch[x][1],s,flag), dfs3(ch[x][0],s,flag);
    else dfs3(ch[x][0],s,flag), dfs3(ch[x][1],s,flag);
}

inline void dfs2(int x)
{
    if(!ch[x][0]) return;
    dfs2(ch[x][0]); dfs2(ch[x][1]);
    for(int i=1;i<=dp[x];i++)
    {
        s1.clear(); s2.clear();
        if(dp[ch[x][0]]+dp[ch[x][1]]<i)
        {
            f[x][i]=f[ch[x][0]][dp[ch[x][0]]]|f[ch[x][1]][dp[ch[x][1]]];
            f[x][i][x]=1;
            continue;
        }
        int c1=min(dp[ch[x][0]],i), c2=min(dp[ch[x][1]],i-c1);
        dfs3(ch[x][0],f[ch[x][0]][c1],1); 
        dfs3(ch[x][1],f[ch[x][1]][c2],1); 

        int d1=min(dp[ch[x][1]],i-1), d2=min(dp[ch[x][0]],i-1-c1);
        dfs3(ch[x][1],f[ch[x][1]][d1],2); 
        dfs3(ch[x][0],f[ch[x][0]][d2],2);

        // if(x==1 && i==2)
        // {
        //     for(int j=0;j<(int)s1.size();j++) cout<<s1[j]<<" ";
        //     cout<<endl;
        //     for(int j=0;j<(int)s2.size();j++) cout<<s2[j]<<" ";
        //     cout<<endl;
        // }

        if(check()) f[x][i]=f[ch[x][0]][d2]|f[ch[x][1]][d1], f[x][i][x]=1;
        else f[x][i]=f[ch[x][0]][c1]|f[ch[x][1]][c2];
    }
}

int main()
{
    n=read(); m=read(); int type;
    for(int i=1;i<=n;i++)
    {
        type=read();
        if(type==1) ch[i][0]=read(), ch[i][1]=read();
        else a[i]=read();
    }
    dfs1(1); dfs2(1);

    // for(int i=1;i<=7;i++) cout<<f[1][2][i]<<" ";
    // cout<<endl;

    s1.clear();
    dfs3(1,f[1][0],1);
    for(int i=m;i>0;i-=2)
    {
        s2.clear();
        dfs3(1,f[1][i],2);
        if(check()) s1=s2;
    }
    for(int i=0;i<(int)s1.size();i++) printf("%d ",s1[i]);
    printf("\n");
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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: 0ms
memory: 3820kb

input:

1 0
2 1000000000

output:

1000000000 

result:

ok 1 number(s): "1000000000"

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 3760kb

input:

3 1
1 2 3
2 1
2 2

output:

1 2 

result:

wrong answer 1st numbers differ - expected: '2', found: '1'