QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#596424#5252. Deforestationhzy99999#WA 80ms6932kbC++201.7kb2024-09-28 15:46:012024-09-28 15:46:01

Judging History

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

  • [2024-09-28 15:46:01]
  • 评测
  • 测评结果:WA
  • 用时:80ms
  • 内存:6932kb
  • [2024-09-28 15:46:01]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<queue>
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 tmp,stk;
bool check(int k,int top) {
    ++stk;
//    printf("[stk=%d]",stk);
    priority_queue <int,vector<int>,greater<int> > Q;
    for(int i=1; i<=k; i++)Q.push(0);
    for(int i=1; i<=top; i++) {
        int t=Q.top();Q.pop();
        if(t+wight[i]>W)return false;
        Q.push(t+wight[i]);
    }
    tmp=Q.top();
    return true;
}
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);
    }
    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);
    if(t[x].d==1)t[x].w+=wight[1],sum=sum+t[x].w/W,t[x].w%=W;
    else if(t[x].d==0) sum=sum+t[x].w/W,t[x].w%=W;
    else {
        int L=1,R=t[x].d,ans=0;
        while(L<=R) {
            int mid=L+R>>1;
            if(check(mid,top))ans=mid,R=mid-1;
            else L=mid+1;
        }
        t[x].w=t[x].w+tmp;
        sum=sum+ans-1+t[x].w/W,t[x].w%=W;
//        printf("ans=%d %d  %d sum=%d\n",ans,t[x].w,t[x].d,sum);
    }
    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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 10ms
memory: 6932kb

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: 80ms
memory: 5904kb

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'