QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#102503#5252. Deforestationcsw_ccc#WA 8ms10712kbC++142.1kb2023-05-03 14:02:482023-05-03 14:02:53

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-03 14:02:53]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:10712kb
  • [2023-05-03 14:02:48]
  • 提交

answer

#include <iostream>
#include <cstring>
#include <map>
#include <cstdio>
#include <queue>
#include <algorithm>
#define ll long long
using namespace std;

struct node
{
	int x;
	int nxt;
};

const int maxn = 100000 + 5;

int Max_w;
node a[maxn << 1];
int len, h[maxn];
int w[maxn];
int chuan[maxn];
int tot;
int ans;

template<class T>
inline void read(T &x);

inline void add(int x, int y)
{
	len++; a[len].x = y; a[len].nxt = h[x]; h[x] = len;
}

void input(int x, int fa)
{
	add(x, fa); add(fa, x);
	int n;
	read(w[x]); read(n);
	
	for (int i = 1; i <= n; i++)
		input(++tot,x);
}

void init()
{
    read(Max_w);
    input(++tot,0);
}

priority_queue<int > q[maxn];

void dfs(int x, int fa)
{
	// printf("x:%d fa:%d w:%d\n",x,fa,w[x]);
	int tot_chuan = 0;
	
	for (int p = h[x]; p; p = a[p].nxt)
	{
		int v = a[p].x;
		if (v == fa) continue;
		dfs(v,x);
		
		if (chuan[v]) q[x].push(chuan[v]), tot_chuan += chuan[v];
	}
	
	if (w[x] >= Max_w)
	{
		ans += w[x] / Max_w;
		if (x != 1) ans++;
		w[x] %= Max_w;
		
		while (tot_chuan > Max_w)
		{
			int t = q[x].top();
			q[x].pop();
			tot_chuan -= t;
			ans++;
		}
		if (tot_chuan + w[x] > Max_w) chuan[x] = w[x] - Max_w + tot_chuan;
		else chuan[x] = 0;
	}
	else
	{
		while (tot_chuan > Max_w)
		{
			int t = q[x].top();
			q[x].pop();
			tot_chuan -= t;
			ans++;
		}
		if (tot_chuan + w[x] > Max_w)
		{
			chuan[x] = w[x] - Max_w + tot_chuan;
			ans++;
		}
		else chuan[x] = tot_chuan + w[x];
	}
}

void work()
{
    dfs(1,0);
	// for (int i = 1; i <= tot; i++) cout << chuan[i] << ' ';
	// puts("");
}

void print()
{
    cout << ans << endl;
}

int main()
{
//    freopen("test.in","r",stdin);
//    freopen("test.out","w",stdout);

    init();
    work();
    print();

    return 0;
}

template<class T>
inline void read(T &x)
{
    x = 0; T s = 1;
    char c = getchar();
    while(c < '0' || c > '9') {if(c == '-') s = -1; c = getchar();}
    while(c >= '0' && c <= '9') {x = x*10+c-'0'; c = getchar();}
    x *= s;
}

详细

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 10712kb

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:

0

result:

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