QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#402749 | #6742. Leaves | altaires1# | WA | 9ms | 32188kb | C++14 | 2.2kb | 2024-05-01 12:23:48 | 2024-05-01 12:23:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=1100;
int n,m;
int arrayA[maxn];
vector<int> dp[maxn][maxn];
vector<int> to[maxn];
int siz[maxn];
void dfs1(int a){
if(to[a].empty()){
siz[a]=0;
return;
}
siz[a]=1;
for(int it : to[a]){
dfs1(it);
siz[a]+=siz[it];
}
return;
}
void dfs(int a){
if(to[a].empty()){
dp[a][0].push_back(arrayA[a]);
return;
}
int l=to[a][0];
int r=to[a][1];
dfs(l);
dfs(r);
for(int i=0;i<=siz[l];i++){
for(int j=0;j<=siz[r];j++){
//先左后右,表示没有交换
vector<int> temp;
int len=0;
for(int it : dp[l][i]){
temp.push_back(it);
len++;
}
for(int it : dp[r][j]){
temp.push_back(it);
len++;
}
if(dp[a][i+j].empty()){
for(int it : temp){
dp[a][i+j].push_back(it);
}
}
else{
int judge=0;
for(int k=0;k<len;k++){
if(dp[a][i+j][k]<temp[k]){
judge=-1;
break;
}
else if(dp[a][i+j][k]>temp[k]){
judge=1;
break;
}
}
if(judge==1){
dp[a][i+j].clear();
for(int it : temp){
dp[a][i+j].push_back(it);
}
}
}
//先右后左,表示交换
if(i+j+1>siz[a]){
continue;
}
temp.clear();
len=0;
for(int it : dp[r][j]){
temp.push_back(it);
len++;
}
for(int it : dp[l][i]){
temp.push_back(it);
len++;
}
if(dp[a][i+j+1].empty()){
for(int it : temp){
dp[a][i+j+1].push_back(it);
}
}
else{
int judge=0;
for(int k=0;k<len;k++){
if(dp[a][i+j+1][k]<temp[k]){
judge=-1;
break;
}
else if(dp[a][i+j+1][k]>temp[k]){
judge=1;
break;
}
}
if(judge==1){
dp[a][i+j+1].clear();
for(int it : temp){
dp[a][i+j+1].push_back(it);
}
}
}
}
}
return;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
int type;
cin>>type;
if(type==1){
int l,r;
cin>>l>>r;
to[i].push_back(l);
to[i].push_back(r);
}
else{
cin>>arrayA[i];
}
}
dfs1(1);
dfs(1);
for(int it : dp[1][m]){
cout<<it<<' ';
}
cout<<'\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 6ms
memory: 32188kb
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: 9ms
memory: 31880kb
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: 4ms
memory: 31936kb
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: 4ms
memory: 31928kb
input:
1 0 2 1000000000
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #5:
score: 0
Accepted
time: 3ms
memory: 31940kb
input:
3 1 1 2 3 2 1 2 2
output:
2 1
result:
ok 2 number(s): "2 1"
Test #6:
score: -100
Wrong Answer
time: 4ms
memory: 31948kb
input:
7 2 1 2 3 1 4 5 1 6 7 2 1 2 2 2 3 2 4
output:
2 1 4 3
result:
wrong answer 1st numbers differ - expected: '1', found: '2'