QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#599657 | #5252. Deforestation | hzy99999 | WA | 13ms | 7888kb | C++20 | 1.4kb | 2024-09-29 08:24:50 | 2024-09-29 08:24:51 |
Judging History
answer
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int n, m, w[N];
vector<int> e[N];
int ans;
bool cmp(int a, int b)
{
return a > b;
}
void dfs(int u)
{
int k;
cin >> w[u] >> k;
for (int i = 1; i <= k; i++)
e[u].push_back(n + 1), dfs(++n);
}
int dfs2(int u)
{
vector<int> cur;
for (int i = 0; i < e[u].size(); i++)
{
int j = e[u][i];
int t = dfs2(j);
ans += t / m;
t %= m;
cur.push_back(t);
}
sort(cur.begin(), cur.end(), cmp);
int l = 0, r = cur.size() - 1;
while (l < r)
{
while (l < r && cur[l] + cur[r] > m)
l++;
if (l < r)
{
cur[l] += cur[r], cur[r] = 0;
if (cur[l] == m)
ans++, cur[l] = 0;
}
r--;
}
int minv = 0x3f3f3f3f, cnt = 0;
for (int i = 0; i < cur.size(); i++)
if (cur[i])
cnt++, minv = min(minv, cur[i]);
if (cnt)
ans += cnt - 1;
return w[u] + (cnt ? minv : 0);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> m;
dfs(++n);
int t = dfs2(1);
ans += (t - 1) / m + 1;
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 13ms
memory: 7888kb
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: 10ms
memory: 6576kb
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'