QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#411836 | #6742. Leaves | AWR | WA | 0ms | 3840kb | C++14 | 1.8kb | 2024-05-15 20:26:15 | 2024-05-15 20:26:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define fir first
#define sec second
#define mpr make_pair
#define vv vector
#define eb emplace_back
#define Fr(i, l, r) for (ll i = l; i <= r; ++i)
#define Rf(i, r, l) for (ll i = r; i >= l; --i)
template<typename T> int Max(T& x, T y) { return y > x ? (x = y, 2) : x == y; }
template<typename T> int Min(T& x, T y) { return y < x ? (x = y, 2) : x == y; }
template<typename T> void Read(T& x) {
x = 0; char ch = getchar(); bool f = false;
while (!isdigit(ch)) f = f || ch == '-', ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
if (f) x = -x;
}
template<typename T> void Write(T x, char ch = '\n') {
static int tp, sk[70];
if (x < 0) putchar('-'), x = -x;
do { sk[++tp] = x % 10, x /= 10; } while (x);
while (tp) putchar('0' + sk[tp--]);
putchar(ch);
}
ll n, m;
ll ls[1010], rs[1010], a[1010];
void Add(vv<ll>& L, vv<ll> R) {
for (auto i : R) L.eb(i);
}
pair<vv<ll>, ll> F(ll x, ll y) {
if (ls[x] == 0) return mpr(vv<ll>(1, a[x]), 0);
auto L = F(ls[x], y);
auto r = F(rs[x], y - L.sec);
Add(L.fir, r.fir), L.sec += r.sec;
if (y == 0) return L;
auto R = F(rs[x], y - 1);
auto l = F(ls[x], y - 1 - R.sec);
Add(R.fir, l.fir), R.sec += l.sec + 1;
if (L.fir < R.fir) {
return L;
} else if (L.fir > R.fir) {
return R;
} else {
if (L.sec < R.sec) return L;
else return R;
}
}
int main() {
Read(n), Read(m);
Fr (i, 1, n) {
ll type; Read(type);
if (type == 1) Read(ls[i]), Read(rs[i]);
else Read(a[i]);
}
auto ans = F(1, m);
ll len = (n + 1) / 2;
Fr (i, 1, len) Write(ans.fir[i - 1], " \n"[i == len]);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
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: 0ms
memory: 3840kb
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: 0ms
memory: 3576kb
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: 0ms
memory: 3568kb
input:
1 0 2 1000000000
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3644kb
input:
3 1 1 2 3 2 1 2 2
output:
1 2
result:
wrong answer 1st numbers differ - expected: '2', found: '1'