QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#536233#5252. DeforestationyqrAC ✓13ms20812kbC++201.8kb2024-08-28 20:56:532024-08-28 20:56:53

Judging History

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

  • [2024-08-28 20:56:53]
  • 评测
  • 测评结果:AC
  • 用时:13ms
  • 内存:20812kb
  • [2024-08-28 20:56:53]
  • 提交

answer

#include<stdio.h>
#include<ctype.h>
#include<vector>
#include<algorithm>
namespace IO {
	constexpr int bufsize = 230005;
	char buf[bufsize], *f1, *f2;
	#define gtchar() (f1 == f2 && (f2 = buf + fread(f1 = buf, 1, bufsize, stdin)) == buf? EOF: *f1++)
	template<typename t> void read(t &ret)
	{
		int f = ret = 0;
		char ch = gtchar();
		while(!isdigit(ch)) f = ch == '-', ch = gtchar();
		while(isdigit(ch)) ret = (ret << 3) + (ret << 1) + (ch ^ 48), ch = gtchar();
		if(f) ret = -ret;
	}
	#undef gtchar
	template<typename t, typename ...T> void read(t &a, T &...b) {read(a), read(b...);}
}using IO::read;
typedef long long ll;
constexpr int maxn = 100005;
int w, n, val[maxn];
ll ans;
std::vector<int> g[maxn];
void readin(int k)
{
	int sz;
	read(val[k], sz);
	for(int i = 1; i <= sz; i++)
		g[k].push_back(++n), readin(n);
}
int dfs(int k)
{
	std::vector<int> p;
	for(int i : g[k])
	{
		int tmp = dfs(i);
		if(tmp) p.push_back(tmp);
	}
	std::sort(p.begin(), p.end());
	int lst = 0, sum = 0;
	while(lst < p.size() && sum + p[lst] <= w) sum += p[lst++];
	ans += p.size() - lst;
	sum += val[k];
	ans += sum / w;
	return sum % w;
}
int main()
{
	// freopen(".in", "r", stdin);
	// freopen(".out", "w", stdout);
	read(w);
	readin(n = 1);
	printf("%lld\n", dfs(1)? ans + 1: ans);
	return 0;
}
/*
考虑叶结点,正确性显然。
合并时,不妨设其儿子子树的贪心策略无误,则该子树策略有误的唯一可能即为将遗留至父亲处理的长度缩减,且缩减后答案只会减少至多 1。但依此策略,各个儿子遗留的长度不必更改,可更改的只有分配的方式。要么将遗留部分再拆一次,要么将连接的儿子断开若干,两者都会将答案加回去甚至更多,故贪心策略无误,不存在更优解
*/

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 8208kb

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: 0
Accepted
time: 4ms
memory: 4808kb

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:

99999

result:

ok single line: '99999'

Test #3:

score: 0
Accepted
time: 13ms
memory: 15492kb

input:

7
10000 2
10000 0
10000 2
10000 0
10000 2
10000 0
10000 2
10000 0
10000 2
10000 0
10000 2
10000 0
10000 2
10000 0
10000 2
10000 0
10000 2
10000 0
10000 2
10000 0
10000 2
10000 0
10000 2
10000 0
10000 2
10000 0
10000 2
10000 0
10000 2
10000 0
10000 2
10000 0
10000 2
10000 0
10000 2
10000 0
10000 2
10...

output:

142862500

result:

ok single line: '142862500'

Test #4:

score: 0
Accepted
time: 4ms
memory: 20812kb

input:

2
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10000 1
10...

output:

500000000

result:

ok single line: '500000000'

Test #5:

score: 0
Accepted
time: 10ms
memory: 8776kb

input:

9717
14907 2
6953 2
10004 2
10949 2
11766 2
14015 2
5640 2
10370 2
6432 2
7602 2
10238 2
9755 2
5788 2
10885 2
11858 2
9182 2
14174 0
12614 0
12080 1
12497 0
7708 2
9108 1
14948 0
9107 1
13540 0
7400 2
6303 2
14462 1
8021 0
7659 1
7232 0
14314 2
9495 1
8459 0
13069 1
5777 0
12734 2
7061 2
12810 2
13...

output:

105756

result:

ok single line: '105756'

Test #6:

score: 0
Accepted
time: 9ms
memory: 9068kb

input:

39375
7550 2
13825 2
11034 2
7836 2
11683 2
9571 2
13888 2
11680 2
5713 2
13175 2
11057 2
7849 2
5598 2
9557 2
7974 2
13285 2
8251 0
13513 0
6254 1
11361 0
13651 2
6286 1
10397 0
5450 1
9590 0
12571 2
7519 2
5512 1
5430 0
9148 1
5281 0
6991 2
6310 1
12868 0
13487 1
6045 0
12298 2
10198 2
11601 2
127...

output:

29976

result:

ok single line: '29976'

Test #7:

score: 0
Accepted
time: 9ms
memory: 8048kb

input:

874898
10304 7
7634 3
7362 9
7960 8
12298 2
5668 1
11762 4
14379 4
6126 1
8135 0
12246 1
13096 0
10376 1
14935 0
9311 0
6256 5
14752 1
12903 0
9645 1
5986 0
14329 0
8683 0
6501 0
6337 1
14416 5
11161 1
10643 0
8900 0
13527 0
9644 0
11961 0
13251 4
9559 1
5799 0
7021 1
13442 0
12589 0
8301 0
5765 7
1...

output:

2116

result:

ok single line: '2116'

Test #8:

score: 0
Accepted
time: 9ms
memory: 7884kb

input:

907686
6329 4
11400 6
5913 8
6890 1
6329 9
10018 5
5234 4
14656 2
11517 0
7330 0
6160 1
11296 1
8221 0
14502 2
14628 0
11846 0
11999 1
5458 0
9845 7
14799 1
9492 0
5534 1
8513 0
12919 1
11676 0
7286 1
8698 0
11372 0
13707 0
12517 0
12094 4
11587 2
5442 0
12160 0
10344 2
13437 0
12069 0
13431 1
9757 ...

output:

2108

result:

ok single line: '2108'

Test #9:

score: 0
Accepted
time: 7ms
memory: 7908kb

input:

19439
9535 1
14066 1
13123 8
14498 10
12761 10
13889 3
5303 4
6155 5
8591 1
9992 0
6323 1
5747 0
12132 1
12189 0
9518 1
11132 0
12872 1
5985 0
12140 1
7932 4
6628 1
9177 0
9398 1
7981 0
7774 1
9833 0
7483 1
12017 0
6505 4
8924 2
8786 0
5604 0
7191 1
14168 0
11672 1
13618 0
8420 1
7884 0
5693 4
12159...

output:

64996

result:

ok single line: '64996'

Extra Test:

score: 0
Extra Test Passed