QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#596133#5252. DeforestationQHhee004#WA 19ms5740kbC++171.8kb2024-09-28 15:12:052024-09-28 15:12:05

Judging History

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

  • [2024-09-28 15:12:05]
  • 评测
  • 测评结果:WA
  • 用时:19ms
  • 内存:5740kb
  • [2024-09-28 15:12:05]
  • 提交

answer

#include<iostream>
#include<algorithm>
using namespace std;
int W,c;
const int N=1e5+5;
struct Tree {
	int w,d;
} t[N];
int wight[N],branch[N];
int tot,hd[N],nxt[N<<1],to[N<<1];
void addedge(int u,int v) {
	++tot,to[tot]=v,nxt[tot]=hd[u],hd[u]=tot;
}
void input(int x,int d) {
	int g=0;
	while(g<d) {
		++g,++c;
		scanf("%d%d",&t[c].w,&t[c].d);
		addedge(x,c);
		input(c,t[c].d);
	}
}
int dfs(int x) {
	int sum=0,top=0;
	for(int i=hd[x]; i; i=nxt[i]) {
		int goal=to[i];
		sum+=dfs(goal);
	}
	wight[1]=0;
	for(int i=hd[x]; i; i=nxt[i])
		if(t[to[i]].w)wight[++top]=t[to[i]].w;
	sort(wight+1,wight+1+top);
	int L=2,R=top,g=1;
	branch[1]=wight[1];
	while(L<=R) {
		branch[++g]=wight[R--];
		while(L<=R&&branch[g]+wight[L]<=W)branch[g]+=wight[L],L++;
	}
//	printf(" w=%d d=%d g=%d\n",t[x].w,t[x].d,g);
	if(t[x].d) {
		if(g==1) {
			t[x].w+=branch[1];
			sum=sum+t[x].w/W,t[x].w%=W;
		} else if(g==2) {
			if(branch[1]+branch[2]<=W) {
				t[x].w+=branch[1]+branch[2];
				sum=sum+t[x].w/W,t[x].w%=W;
//				printf("  [1] sum=%lld x=%d %d\n",sum,x,t[x].w);
			} else {
				t[x].w+=branch[1];
				sum=sum+t[x].w/W+1,t[x].w%=W;
//				printf("  [2] sum=%lld x=%d %d\n",sum,x,t[x].w);
			}
		} else {
			sort(branch+2,branch+1+g);
			if(branch[1]+branch[3]<=W) {
				t[x].w+=branch[2];
				sum=sum+t[x].w/W+g-2,t[x].w%=W;
			} else if(branch[1]+branch[2]<=W) {
				t[x].w+=branch[1]+branch[2];
				sum=sum+t[x].w/W+g-2,t[x].w%=W;
			} else {
				t[x].w+=branch[1];
				sum=sum+t[x].w/W+g-1,t[x].w%=W;
			}
		}
	} else {
		sum=sum+t[x].w/W,t[x].w%=W;
	}
	printf("sum=%lld x=%d %d\n",sum,x,t[x].w);
	return sum;
}
int main() {
	scanf("%d",&W);
	++c;
	scanf("%d%d",&t[c].w,&t[c].d);
	input(1,t[1].d);
	printf("%d\n",dfs(1)+(t[1].w!=0));
	return 0;
}


详细

Test #1:

score: 0
Wrong Answer
time: 19ms
memory: 5740kb

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:

sum=0 x=100000 9004
sum=0 x=99999 7354
sum=0 x=99998 12830
sum=0 x=99997 12151
sum=0 x=99996 8044
sum=0 x=99995 14901
sum=0 x=99994 22390
sum=0 x=99993 8372
sum=0 x=99992 22268
sum=0 x=99991 7880
sum=0 x=99990 17289
sum=0 x=99989 14729
sum=0 x=99988 26232
sum=0 x=99987 148430
sum=0 x=99986 14343
sum...

result:

wrong answer 1st lines differ - expected: '1', found: 'sum=0 x=100000 9004'