QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#102470 | #5252. Deforestation | gudu | WA | 19ms | 11116kb | C++14 | 964b | 2023-05-03 13:38:12 | 2023-05-03 13:38:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M (998244353)
#define N (200010)
int w,m,n,cnt,total,id=1,x;
int head[N],to[N],nx[N],a[N],t[N],son[N],Sum[N];
void add(int x,int y){
++cnt; to[cnt]=y,nx[cnt]=head[x],head[x]=cnt;
// ++cnt; to[cnt]=x,nx[cnt]=head[y],head[y]=cnt;
}
void read(int fa,int now){
add(fa,now); a[now]=x;
scanf("%d%d",&x,&son[now]);
for (int i=1;i<=son[now];++i) read(now,++id);
}
void dfs(int x,int L){
int Cnt=0,sum=0; Sum[x]=son[x];
for (int i=head[x];i;i=nx[i]){
int y=to[i];
dfs(y,L+Sum[x]); Sum[x]+=son[y];
sum+=a[y],t[L+Cnt]=a[y]; ++Cnt;
}
if (sum<w) total+=(a[x]+sum)/w,a[x]=(a[x]+sum)%w;
else{
sort(t+L,t+L+son[x]);
int j=L; sum=0;
while (j<=L+son[x]-1&&sum+t[j]<w) sum+=t[j],++j;
total+=(L+son[x]-j)+(a[x]+sum)/w; a[x]=(a[x]+sum)%w;
}
}
int main(){
scanf("%d",&w);
read(0,1);
dfs(1,1);
printf("%d\n",total+(a[1]!=0));
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 19ms
memory: 5960kb
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: 18ms
memory: 5960kb
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: -100
Wrong Answer
time: 10ms
memory: 11116kb
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:
142861072
result:
wrong answer 1st lines differ - expected: '142862500', found: '142861072'