比赛 EYOI与SBOI开学欢乐赛2nd 评测结果 AAAWTW
题目名称 免费馅饼 最终得分 50
用户昵称 HeSn 运行时间 1.737 s
代码语言 C++ 内存使用 9.02 MiB
提交时间 2022-09-02 20:48:44
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int w, h, n, final[100010], act[100010], maxn, ans, num;
vector<int> a[110], b[110];
bool vis[100010];
struct node {
	int x, t, v;
}c[1000010];
void dfs(int x, int cs, int to, int t, int s) {
//	cout << x << ' ' << cs << ' ' << to << ' ' << t << ' ' << s << endl;
	if(x == c[to].x && to != 0) {
		while(t < c[to].t) {
			t ++;
			cs ++;
			act[cs] = 0;
		}
		s += c[to].v;
	}
	if(t >= maxn) {
		if(s > ans) {
			num = cs;
			ans = s;
			for(int i = 1; i <= cs; i ++) {
				final[i] = act[i];
			}
		}
		if(s == ans) {
			if(num < cs) {
				return ;
			}
			bool f = 0;
			for(int i = 1; i <= cs; i ++) {
				if(act[i] < final[i]) {
					f = 1;
					break;
				}
			}
			if(f) {
				for(int i = 1; i <= cs; i ++) {
					final[i] = act[i];
				}
				num = cs;
			}
		}
		return ;
	}
	if(x != c[to].x && to != 0) {
		if(x > c[to].x) {
			while(x - c[to].x >= 2) {
				x -= 2;
				t ++;
				cs ++;
				act[cs] = -2;
			}
			if(x != c[to].x) {
				t ++;
				x --;
				cs ++;
				act[cs] = -1;
			}
			dfs(x, cs, to, t, s);
		}
		else {
			while(c[to].x - x >= 2) {
				x += 2;
				t ++;
				cs ++;
				act[cs] = 2;
			}
			if(x != c[to].x) {
				t ++;
				x ++;
				cs ++;
				act[cs] = 1;
			}
			dfs(x, cs, to, t, s);
		}
		return ;
	}
	for(int i = 1; i <= n; i ++) {
		int u = abs(c[i].x - x);
		if(c[i].t >= t + u / 2 + u % 2 && !vis[i]) {
//			cout << i << endl;
			vis[i] = 1;
			dfs(x, cs, i, t, s);
			vis[i] = 0;
		}
	}
}
int main() {
	freopen("freepizza.in", "r", stdin);
	freopen("freepizza.out", "w", stdout);
	cin >> w >> h;
	int x, y, ww, z;
	while(cin >> x >> y >> ww >> z) {
		if(h % ww != 1 && ww != 1) {
			continue;
		}
		++ n;
		c[n].x = y;
		c[n].t = h / ww + x;
		c[n].v = z;
		if(ww == 1) {
			c[n].t --;
		}
		maxn = max(maxn, c[n].t);
	}
//	for(int i = 1; i <= n; i ++) {
//		cout << c[i].x << ' ' << c[i].t << ' ' << c[i].v << endl;
//	}
//	cout << w / 2 + 1 << endl;
	dfs(w / 2 + 1, 0, 0, 0, 0);
	cout << ans << endl;
	for(int i = 1; i <= num; i ++) {
		cout << final[i] << endl;
	}
	return 0;
}