QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#751603#6742. LeavesayaWA 1ms5796kbC++231.1kb2024-11-15 19:39:302024-11-15 19:39:30

Judging History

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

  • [2024-11-15 19:39:30]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5796kb
  • [2024-11-15 19:39:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m,l[1004],r[1004],a[1004],b[1004];
int f[1004][504],g[504][504],h[504];
bool check(int *x,int *y,int k){for(int i=0;i<k;i++)if(x[i]^y[i])return x[i]<y[i];return 0;}
void dfs0(int x){
	int ls=l[x],rs=r[x];
	if(rs)dfs0(ls),dfs0(rs),a[x]=a[ls]+a[rs]+1,b[x]=b[ls]+b[rs];else b[x]=1;
}
void dfs(int x,int L){
	int ls=l[x],rs=r[x];
	if(!rs){f[L][0]=ls;return;}
	int R=L+a[ls]+b[ls],k=b[x];
	dfs(ls,L),dfs(rs,R);
	for(int i=0;i<=a[x];i++){
		memset(g[i],0x3f,k<<2);
		for(int j=max(0,i-a[rs]-1);j<=min(a[ls],i);j++){
			if(j!=i-a[rs]-1){
				memcpy(h,f[L+j],b[ls]<<2),memcpy(h+b[ls],f[R+i-j],b[rs]<<2);
				if(check(h,g[i],k))memcpy(g[i],h,k<<2);
			}
			if(j!=i){
				memcpy(h,f[R+i-j-1],b[rs]<<2),memcpy(h+b[rs],f[L+j],b[ls]<<2);
				if(check(h,g[i],k))memcpy(g[i],h,k<<2);
			}
		}
		memcpy(f[L+i],g[i],k<<2);
	}
	for(int i=0;i<=a[x];i++)memcpy(f[L+i],g[i],k<<2);
}
int main(){
	ios::sync_with_stdio(false),cin.tie(0);
	cin>>n>>m;
	for(int i=1,t;i<=n;i++){cin>>t>>l[i];if(t<2)cin>>r[i];}
	dfs0(1),dfs(1,0);
	for(int i=0;i<b[1];i++)cout<<f[m][i]<<' ';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5744kb

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

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

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

input:

1 0
2 1000000000

output:

1000000000 

result:

ok 1 number(s): "1000000000"

Test #5:

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

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

input:

7 2
1 2 3
1 4 5
1 6 7
2 1
2 2
2 3
2 4

output:

1 2 4 3 

result:

wrong answer 3rd numbers differ - expected: '3', found: '4'