QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#411941#6742. LeavesYnoiynoi#Compile Error//C++142.8kb2024-05-15 21:58:002024-05-15 21:58:00

Judging History

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

  • [2024-05-15 21:58:00]
  • 评测
  • [2024-05-15 21:58:00]
  • 提交

answer

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

#define MAXN 1005
#define int long long
const int INF = 1e18;

int n,m;
int a[MAXN];
struct aa {
	int a[MAXN],nn;
	void wt() {
		for(int i = 1; i <= nn; i ++)
			cout<<a[i]<<" ";
		cout<<"\n";
	}
};

aa merge(aa a,aa b) {
	aa c;
	c.nn = 0;
	c.nn = a.nn+b.nn;
	for(int i = 1; i <= a.nn; i ++) 
		c.a[i] = a.a[i];
	for(int i = 1; i <= b.nn; i ++) 
		c.a[i+a.nn] = b.a[i];
	return c;
}

bool operator <(aa a,aa b) {
	for(int i = 1; i <= a.nn; i ++) {
		if(a.a[i] > b.a[i]) return 0;
		if(a.a[i] < b.a[i]) return 1;
	}
	return 0;
}

aa f[MAXN],b[MAXN];
int c[MAXN],zw[MAXN];
int lc[MAXN],rc[MAXN];

void dfs(int x) {
//	cout<<x<<"\n";
	if(a[x] != 0) {
		f[x].nn = 1;
		f[x].a[1] = a[x];
		b[x] = f[x];
		return;
	}
	dfs(lc[x]);
	dfs(rc[x]);
	b[x] = merge(b[lc[x]],b[rc[x]]);
	c[x] = c[lc[x]]+c[rc[x]];
	aa f1 = merge(f[lc[x]],f[rc[x]]);
	aa f2 = merge(f[rc[x]],f[lc[x]]);
	zw[x] = zw[lc[x]]+zw[rc[x]];
	
	if(f1 < f2) {
		f[x] = f1;
		return;
	} else {
		f[x] = f2;
		if(f2 < f1) {
			c[x] ++; zw[x] ++;
		 } else zw[x] = -INF;
		return;
	}
}

int rt; 
int ew[MAXN];
aa p[MAXN];
//map<int,aa>pp[MAXN];

aa orz(int x,int m,int &zp) {
	//cout<<x<<" "<<m<<"\n";
	if(pp[x].count(m)) return pp[x][m];
	if(a[x] != 0) return b[x];

	if(m == 0) {
		return b[x];
	}
//	if(m >= c[x]) return f[x];
	aa f1,f2;
	bool d1 = 0,d2 = 0;
	int z11 = 0,z12 = 0,z21 = 0,z22 = 0;
	if(c[lc[x]] <= m) {
		d1 = 1; f1 = merge(f[lc[x]],orz(rc[x],m-c[lc[x]],z21));
	} else f1 = merge(orz(lc[x],m,z12),b[rc[x]]);
	
	if(c[rc[x]] <= m-1) {
		d2 = 1; f2 = merge(f[rc[x]],orz(lc[x],m-1-c[lc[x]],z11));
	} else f2 = merge(orz(rc[x],m-1,z22),b[lc[x]]);
/*	cout<<x<<":----\n";
	f1.wt();
	f2.wt();
	cout<<d1<<" "<<d2<<"?\n";*/
	if(f1 < f2) {
		if(d1) zp = zw[lc[x]] + z21;
		else zp = z12;
		pp[x][m] = f1;
	//	cout<<x<<" "<<m<<" "<<zp<<"\n";
		return f1;
	} else {
		if(f2 < f1)	{
			if(d2) zp = z11+zw[rc[x]]+1;
			else zp = z22+1;
		} else zp = -INF;
		pp[x][m] = f2;
		//cout<<x<<" "<<m<<" "<<zp<<"??\n";
		return f2;
	}
}

int cc[MAXN];

bool eq(aa a,aa b) {
	for(int i = 1; i <= a.nn; i ++)
	if(a.a[i] != b.a[i]) return 0;
	return 1;
}
aa an;
aa w[MAXN];


signed main() {
	cin >> n >> m;
	for(int i = 1; i <= n; i ++) {
		int op;
		cin >> op;
		if(op == 1) {
			cin >> lc[i] >> rc[i];
		}	else cin >> a[i];
	}
	dfs(1);
	int zp = -1;
	an = orz(1,m,zp);
	/*for(int i = 1; i <= n; i ++)
		cout<<zp[i]<<" ";
	cout<<"\n";*/
	if(zp >= 0 && zp%2 != m%2) swap(an.a[an.nn],an.a[an.nn-1]);
	for(int i = 1; i <= an.nn; i ++)
		cout<<an.a[i]<<" ";
	return 0; 
}
/*
7 1
1 2 3
1 4 5
1 6 7
2 4
2 2
2 3
2 1

3 2
1 2 3
2 2
2 1

9 2 
1 2 3
1 8 9 
1 4 5
1 6 7
2 20 
2 30 
2 1
2 3
2 3 

*/

Details

answer.code: In function ‘aa orz(long long int, long long int, long long int&)’:
answer.code:77:12: error: ‘pp’ was not declared in this scope; did you mean ‘zp’?
   77 |         if(pp[x].count(m)) return pp[x][m];
      |            ^~
      |            zp
answer.code:101:17: error: ‘pp’ was not declared in this scope; did you mean ‘zp’?
  101 |                 pp[x][m] = f1;
      |                 ^~
      |                 zp
answer.code:109:17: error: ‘pp’ was not declared in this scope; did you mean ‘zp’?
  109 |                 pp[x][m] = f2;
      |                 ^~
      |                 zp