QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#140984 | #6742. Leaves | UFRJ# | WA | 3ms | 7020kb | C++20 | 1.2kb | 2023-08-17 03:31:05 | 2023-08-17 03:31:08 |
Judging History
answer
#include<bits/stdc++.h>
using lint = int64_t;
using namespace std;
int main(void) {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m;
cin>>n>>m;
vector<int>a(n, -1), l(n, -1), r(n, -1);
for(int i=0;i<n;i++){
int type;
cin>>type;
if(type == 1) cin>>l[i]>>r[i], l[i]--, r[i]--;
else cin>>a[i];
}
vector<vector<int>>dp(n, vector<int>(n+1, n + 10));
for(int i=n-1;i>=0;i--){
if(a[i] != -1){
for(int j=0;j<=n;j++) dp[i][j] = a[i];
}
else{
dp[i][0] = dp[l[i]][0];
for(int j=1;j<=n;j++) dp[i][j] = min(dp[l[i]][j], dp[r[i]][j-1]);
}
}
vector<int>ans;
auto go = [&](auto& self, int v, int k)->int {
if(l[v] == -1){
ans.push_back(a[v]);
return k;
}
if(k && dp[l[v]][k] > dp[r[v]][k-1]){
int c = self(self, r[v], k - 1);
int d = self(self, l[v], c);
return d;
}
else{
int c = self(self, l[v], k);
int d = self(self, r[v], c);
return d;
}
};
int rest = go(go, 0, m);
int sz = ans.size();
if(rest&1) swap(ans[sz-2], ans[sz-1]);
for(int u : ans) cout<<u<<" ";
cout<<"\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3528kb
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: 3472kb
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: 3520kb
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: 3576kb
input:
1 0 2 1000000000
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3532kb
input:
3 1 1 2 3 2 1 2 2
output:
2 1
result:
ok 2 number(s): "2 1"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3456kb
input:
7 2 1 2 3 1 4 5 1 6 7 2 1 2 2 2 3 2 4
output:
1 2 3 4
result:
ok 4 number(s): "1 2 3 4"
Test #7:
score: -100
Wrong Answer
time: 3ms
memory: 7020kb
input:
999 480 1 3 2 1 4 5 1 6 7 1 9 8 1 10 11 1 13 12 1 14 15 1 16 17 1 19 18 1 21 20 1 23 22 1 25 24 1 27 26 1 28 29 1 30 31 1 33 32 1 35 34 1 37 36 1 38 39 1 41 40 1 42 43 1 45 44 1 46 47 1 48 49 1 51 50 1 52 53 1 55 54 1 56 57 1 58 59 1 61 60 1 62 63 1 64 65 1 67 66 1 69 68 1 71 70 1 73 72 1 74 75 1 76...
output:
34826804 763875883 763875883 763875883 763875883 763875883 763875883 763875883 248820103 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 7...
result:
wrong answer 104th numbers differ - expected: '763875883', found: '807426271'