QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#483317#6743. water235ucup-team052#RE 0ms0kbC++142.7kb2024-07-18 15:28:012024-07-18 15:28:01

Judging History

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

  • [2024-07-18 15:28:01]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-07-18 15:28:01]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define D(...) fprintf(stderr,__VA_ARGS__)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
using namespace std;
const int N=1005;
int n,m,type[N],lc[N],rc[N],a[N],sz[N];
vector<vector<int> >dp[2][N];
vector<int>tt[2][N];
vector<int>operator+(const vector<int>&lhs,const vector<int>&rhs){
	vector<int>ret(SZ(lhs)+SZ(rhs));
	rep(i,0,SZ(lhs)-1)ret[i]=lhs[i];
	rep(i,SZ(lhs),SZ(ret)-1)ret[i]=rhs[i-SZ(lhs)];
	return ret;
}
vector<int>Min(const vector<int>&lhs,const vector<int>&rhs){
	if(lhs.empty())return rhs;
	if(rhs.empty())return lhs;
	assert(SZ(lhs)==SZ(rhs));
	return min(lhs,rhs);
}
void solve(int u){
	if(type[u]==1){
		solve(lc[u]),solve(rc[u]);
		sz[u]=sz[lc[u]]+sz[rc[u]];
		dp[0][u].resize(sz[u]);
		dp[1][u].resize(sz[u]);
		rep(o0,0,1)if(!dp[o0][lc[u]].empty())rep(o1,0,1)if(!dp[o1][rc[u]].empty()){
			rep(i,0,SZ(dp[o0][lc[u]])-1+SZ(dp[o1][rc[u]])-1){
				vector<int>V0(dp[o0][lc[u]][i<SZ(dp[o0][lc[u]])?i:SZ(dp[o0][lc[u]])-1]);
				vector<int>V1(dp[o1][rc[u]][i<SZ(dp[o0][lc[u]])?min(tt[o0][lc[u]][i],SZ(dp[o1][rc[u]])-1):i-SZ(dp[o0][lc[u]])+1]);
				dp[(o0+o1)&1][u][(o0+o1)/2+i]=Min(dp[(o0+o1)&1][u][(o0+o1)/2+i],V0+V1);
			}
		}
		swap(lc[u],rc[u]);
		rep(o0,0,1)if(!dp[o0][lc[u]].empty())rep(o1,0,1)if(!dp[o1][rc[u]].empty()){
			rep(i,0,SZ(dp[o0][lc[u]])-1+SZ(dp[o1][rc[u]])-1){
				vector<int>V0(dp[o0][lc[u]][i<SZ(dp[o0][lc[u]])?i:SZ(dp[o0][lc[u]])-1]);
				vector<int>V1(dp[o1][rc[u]][i<SZ(dp[o0][lc[u]])?min(tt[o0][lc[u]][i],SZ(dp[o1][rc[u]])-1):i-SZ(dp[o0][lc[u]])+1]);
				dp[(o0+o1+1)&1][u][(o0+o1+1)/2+i]=Min(dp[(o0+o1+1)&1][u][(o0+o1+1)/2+i],V0+V1);
			}
		}
		swap(lc[u],rc[u]);
		rep(o,0,1){
			while(dp[o][u].back().empty())dp[o][u].pop_back();
			while(SZ(dp[o][u])>1&&dp[o][u].back()==dp[o][u][SZ(dp[o][u])-2])dp[o][u].pop_back();
		}
		rep(o,0,1){
			dp[o][lc[u]].clear();
			dp[o][lc[u]].shrink_to_fit();
			dp[o][rc[u]].clear();
			dp[o][rc[u]].shrink_to_fit();
			tt[o][lc[u]].clear();
			tt[o][lc[u]].shrink_to_fit();
			tt[o][rc[u]].clear();
			tt[o][rc[u]].shrink_to_fit();
		}
		rep(o,0,1){
			tt[o][u].resize(SZ(dp[o][u]));
			rep(i,1,SZ(tt[o][u])-1){
				if(dp[o][u][i]==dp[o][u][i-1]){
					tt[o][u][i]=tt[o][u][i-1]+1;
				}else{
					tt[o][u][i]=0;
				}
			}
		}
	}else{
		dp[0][u].pb(vector<int>{a[u]});
		sz[u]=1;
	}
}
int main(){
#ifdef xay5421
	freopen("a.in","r",stdin);
#endif
	cin>>n>>m;
	rep(i,1,n){
		cin>>type[i];
		if(type[i]==1){
			cin>>lc[i]>>rc[i];
		}else{
			cin>>a[i];
		}
	}
	solve(1);
	vector<int>ans(dp[m&1][1][min(m/2,SZ(dp[m&1][1])-1)]);
	rep(i,0,SZ(ans)-1)printf("%d ",ans[i]);
	return 0;
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

2 1

output:


result: