QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#90253 | #5252. Deforestation | chiranko# | WA | 23ms | 31672kb | C++14 | 1.8kb | 2023-03-22 15:39:49 | 2023-03-22 15:39:50 |
Judging History
answer
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using LL = long long;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int W;
cin >> W;
const int maxn = 1e6 + 5;
int cur = 0;
vector<int> E[maxn], val(maxn, 0);
function<void(int)> read_tree = [&](int x){
int sz;
cin >> val[x] >> sz;
for(int i = 1; i <= sz; ++i){
++cur;
E[x].pb(cur);
read_tree(cur);
}
};
read_tree(++cur);
int ans = 0;
function<int(int)> dfs = [&](int x){
int n = E[x].size();
vector<int> res(n + 1, 0), G(n + 1, 0);
for(int i = 0; i <= n - 1; ++i){
res[i] = dfs(E[x][i]);
}
int sufsum = 0, suf = 0;
for(int i = n - 1; i >= 0; --i){
sufsum += res[i];
if(sufsum >= W){
sufsum -= W;
++suf;
}
G[i] = suf + (sufsum > 0);
}
if(!n){
ans += (val[x] / W);
return val[x] % W;
}
int mi = G[0];
int sum = 0;
int pre = 0, presum = 0, pr = 0;
int mires = 1e9 + 5;
// {
// cerr << "res\n";
// for(int i = 0; i <= n - 1; ++i){
// cerr << res[i] << " ";
// }
// cerr << '\n';
// }
for(int i = 0; i <= n - 1; ++i){
while(pr <= n - 1 && pre + (presum > 0) + G[pr] + 1 > G[0]){
sum += res[pr];
++pr;
}
// cerr << "now " << i << " " << pr << " " << sum << " " << pre << " " << '\n';
int t = pre + (presum > 0) + G[pr] + 1;
if(t == G[0] && sum <= W){
mires = min(mires, sum);
}
sum -= res[i];
presum += res[i];
if(presum >= W){
presum -= W;
++pre;
}
}
ans += G[0] - 1 + (mires + val[x]) / W;
// cerr << "last " << G[0] << " " << mires << " " << G[0] - 1 + (mires + val[x]) / W << " " << val[x] << '\n';
return (mires + val[x]) % W;
};
cout << ans + (dfs(1) > 0);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 23ms
memory: 31632kb
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: 16ms
memory: 31672kb
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'