QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#145307 | #6742. Leaves | berarchegas# | WA | 4ms | 17048kb | C++17 | 1.8kb | 2023-08-22 04:58:30 | 2023-08-22 04:58:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
const int MAXN = 1e3 + 5;
const ll INF = 2e18;
vector<int> dp[1005][505];
int qtd[1005][505];
int val[MAXN], l[MAXN], r[MAXN], n, m;
void dfs(int node) {
if (val[node]) {
for (int i = 0; i <= m; i++) {
dp[node][i] = {val[node]};
qtd[node][i] = 0;
}
return;
}
dfs(l[node]);
dfs(r[node]);
for (int i = 0; i <= m; i++) {
if (!i) {
dp[node][0] = dp[l[node]][0];
for (int x : dp[r[node]][0]) dp[node][0].push_back(x);
}
else {
if (dp[l[node]][i] >= dp[r[node]][i - 1]) {
int use = min(i - 1, qtd[r[node]][i - 1]);
dp[node][i] = dp[r[node]][use];
for (int x : dp[l[node]][i - use - 1]) dp[node][i].push_back(x);
qtd[node][i] = qtd[r[node]][use] + qtd[l[node]][i - use - 1] + 1;
}
else {
int use = min(i, qtd[l[node]][i]);
dp[node][i] = dp[l[node]][use];
for (int x : dp[r[node]][i - use]) dp[node][i].push_back(x);
qtd[node][i] = qtd[l[node]][use] + qtd[r[node]][i - use];
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
int tipo, a, b;
for (int i = 1; i <= n; i++) {
cin >> tipo;
if (tipo == 1) {
cin >> a >> b;
l[i] = a;
r[i] = b;
}
else {
cin >> val[i];
}
}
dfs(1);
for (int x : dp[1][m]) cout << x << ' ';
cout << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 16844kb
input:
3 0 1 2 3 2 1 2 2
output:
1 2
result:
ok 2 number(s): "1 2"
Test #2:
score: 0
Accepted
time: 1ms
memory: 16932kb
input:
7 1 1 2 3 1 4 5 1 6 7 2 4 2 2 2 3 2 1
output:
2 4 3 1
result:
ok 4 number(s): "2 4 3 1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 15736kb
input:
7 2 1 2 3 1 4 5 1 6 7 2 4 2 2 2 3 2 1
output:
1 3 4 2
result:
ok 4 number(s): "1 3 4 2"
Test #4:
score: 0
Accepted
time: 1ms
memory: 16896kb
input:
1 0 2 1000000000
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 17048kb
input:
3 1 1 2 3 2 1 2 2
output:
1 2
result:
wrong answer 1st numbers differ - expected: '2', found: '1'