QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#410501#5252. Deforestationucup-team1716#WA 287ms9396kbC++142.1kb2024-05-14 03:41:112024-05-14 03:41:12

Judging History

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

  • [2024-05-14 03:41:12]
  • 评测
  • 测评结果:WA
  • 用时:287ms
  • 内存:9396kb
  • [2024-05-14 03:41:11]
  • 提交

answer

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

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

const int MAXN = 1e5;
const int INF = 1e9;

int n, 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) { // 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 - 1;
		while (l < r) {
			int mid = (l + r) / 2;
			if (get_min_count2(a, mid - m) == mc) {
				r = mid;
			} else {
				l = mid + 1;
			}
		}
		
		res = mk(mc - 1, l);
	}
	
	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: 287ms
memory: 3460kb

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: 81ms
memory: 9396kb

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'