QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#145309 | #6742. Leaves | berarchegas | WA | 5ms | 17308kb | C++17 | 2.5kb | 2023-08-22 05:17:55 | 2023-08-22 05:17:56 |
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]);
vector<int> minL = dp[l[node]][0], minR = dp[r[node]][0];
int opL = 0, opR = 0;
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] < minL) {
minL = dp[l[node]][i];
opL = i;
}
if (minL < minR) {
dp[node][i] = minL;
for (int x : dp[r[node]][i - opL]) dp[node][i].push_back(x);
}
else if (minL > minR) {
dp[node][i] = minR;
for (int x : dp[l[node]][i - 1 - opR]) dp[node][i].push_back(x);
}
else {
vector<int> a, b;
for (int x : dp[l[node]][i - 1 - opR]) a.push_back(x);
for (int x : dp[r[node]][i - opL]) b.push_back(x);
if (a < b) {
dp[node][i] = minR;
for (int x : a) dp[node][i].push_back(x);
}
else {
dp[node][i] = minL;
for (int x : b) dp[node][i].push_back(x);
}
}
if (dp[r[node]][i] < minR) {
minR = dp[r[node]][i];
opR = i;
}
if (i >= 2) {
dp[node][i] = min(dp[node][i], dp[node][i - 2]);
}
}
}
}
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: 5ms
memory: 15760kb
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: 15660kb
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: 15464kb
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: 16772kb
input:
1 0 2 1000000000
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #5:
score: -100
Wrong Answer
time: 5ms
memory: 17308kb
input:
3 1 1 2 3 2 1 2 2
output:
1 2
result:
wrong answer 1st numbers differ - expected: '2', found: '1'