QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#410502#5252. Deforestationucup-team1716#WA 294ms9380kbC++142.2kb2024-05-14 04:23:042024-05-14 04:23:04

Judging History

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

  • [2024-05-14 04:23:04]
  • 评测
  • 测评结果:WA
  • 用时:294ms
  • 内存:9380kb
  • [2024-05-14 04:23:04]
  • 提交

answer

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

#define fi first
#define se second
#define mk make_pair

const int INF = 1e9;

int W, ans;

int get_min_count(vector<int> a) {
	multiset<int> ms;
	for (int i = 0; i < (int)a.size(); ++i) {
		ms.insert(a[i]);
	}
	
	int res = 0;
	
	while (!ms.empty()) {
		int remaining = W;
		while (remaining > 0) {
			multiset<int>::iterator it = ms.upper_bound(remaining);
			if (it == ms.begin()) {
				break;
			}
			--it;
			remaining -= (*it);
			ms.erase(it);
		}
		
		res++;
	}
	
	return res;
}

int get_min_count2(vector<int> a, int lim) {
	multiset<int> ms;
	for (int i = 0; i < (int)a.size(); ++i) {
		ms.insert(a[i]);
	}
	
	int res = 0;
	
	while (!ms.empty()) {
		int remaining = (res ? W : lim); // use lim if it is the first time
		while (remaining > 0) {
			multiset<int>::iterator it = ms.upper_bound(remaining);
			if (it == ms.begin()) {
				break;
			}
			--it;
			remaining -= (*it);
			ms.erase(it);
		}
		
		res++;
	}
	
	return res;
}

int dfs() {
	int m, num;
	cin >> m >> num;
	
	vector<int> a;
	
	for (int i = 1; i <= num; ++i) {
		int x = dfs();
		assert(x < W);
		if (x > 0) {
			a.push_back(x);
		}
	}
	
	pair<int, int> res = mk(INF, INF);
	if (m < W) { // CASE 1: don't cut, not even at the very top (i.e., the returned weight >= m)
		vector<int> tmp = a;
		tmp.push_back(m);
		int mc = get_min_count(tmp);
		
		int l = m, r = W;
		while (l < r) {
			int mid = (l + r) / 2;
			if (get_min_count2(a, mid - m) == mc) {
				r = mid;
			} else {
				l = mid + 1;
			}
		}
		
		if (l == W) {
			res = mk(mc, 0);
		} else {
			res = mk(mc - 1, l);
		}
	}
	
	// CASE 2: cut (means that we will give something down)
	int mc = get_min_count(a);
	int l = 0, r = min(m, W);
	while (l < r) { // give down as much (large) as possible
		int mid = (l + r + 1) / 2;
		
		vector<int> tmp = a;
		tmp.push_back(mid);
		
		if (get_min_count(tmp) == mc) {
			l = mid;
		} else {
			r = mid - 1;
		}
	}
	
	int len = m - l;
	res = min(res, mk(mc + len / W, len % W));
	
	ans += res.fi;
	
	return res.se;
}

int main() {
	cin >> W;
	if (dfs()) {
		ans++;
	}
	cout << ans << endl;
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 294ms
memory: 3680kb

input:

999900000
7339 3
14947 2
12850 3
8986 10
11599 9
8889 10
10711 4
8015 1
11626 0
9492 1
7017 0
8863 0
8632 0
5321 5
9906 0
11687 0
9845 0
10469 0
11708 0
14950 5
11934 0
11922 0
13101 0
12000 0
9082 0
9273 5
12296 0
6119 0
9201 0
12652 0
12957 0
7454 5
12515 0
12976 0
10358 0
13997 0
8371 0
10181 5
8...

output:

1

result:

ok single line: '1'

Test #2:

score: -100
Wrong Answer
time: 95ms
memory: 9380kb

input:

2
1 99999
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 ...

output:

50000

result:

wrong answer 1st lines differ - expected: '99999', found: '50000'