QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#396955#6742. LeavesskulkerWA 4ms21320kbC++201.9kb2024-04-23 14:48:372024-04-23 14:48:38

Judging History

你现在查看的是最新测评结果

  • [2024-04-23 14:48:38]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:21320kb
  • [2024-04-23 14:48:37]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
using namespace std;
int n,m;
string dp[1100][510];

int lf[110];
int siz[1100];

vector<int> nex[1100];
string val[1100];

void dfs(int now){
    siz[now]=1;
    lf[now]=0;
    if(nex[now].size()==0){
        lf[now]=1;
        dp[now][0]=val[now];
        dp[now][0]=dp[now][0]+" ";
        return ;
    }
    else {
        for(int i=0;i<nex[now].size();i++){
            dfs(nex[now][i]);
            siz[now]=siz[now]+siz[nex[now][i]];
            lf[now]=lf[now]+lf[nex[now][i]];
        }
    }
    int l=nex[now][0],r=nex[now][1];
    for(int i=0;i<=(siz[l]-1)/2;i++){
        for(int j=0;j<=(siz[r]-1)/2&&i+j<=m;j++){
            string s2=dp[l][i]+dp[r][j];
            if(dp[now][i+j].size()==0){
                dp[now][i+j]=s2;
            }
            else {
                if(dp[now][i+j]>s2) {
                    dp[now][i+j]=s2;
                }
            }
        }
    }
    l=nex[now][1],r=nex[now][0];
    for(int i=0;i<=(siz[l]-1)/2;i++){
        for(int j=0;j<=(siz[r]-1)/2&&i+j+1<=m;j++){
            string s2=dp[l][i]+dp[r][j];
            if(dp[now][i+j+1].size()==0){
                dp[now][i+j+1]=s2;
            }
            else {
                if(dp[now][i+j+1]>s2) dp[now][i+j+1]=s2;
            }
//            cout<<"swp l r i="<<i<<" j="<<j<<" dp[now][i+j+1]="<<dp[now][i+j+1]<<'\n';
        }
    }
}
int main(){
    scanf("%d%d",&n,&m);
    int u,v,w;
    int opt;
    for(int i=1;i<=n;i++){
        scanf("%d",&opt);
        if(opt==1){
            scanf("%d%d",&u,&v);
            nex[i].push_back(u);
            nex[i].push_back(v);
        }
        else {
            cin>>val[i];
        }
    }
    dfs(1);
    string ans=dp[1][0];
    for(int i=1;i<=m;i++) {
        if(dp[1][i]<ans) ans=dp[1][i];
    }
    cout<<ans;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 21244kb

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: 4ms
memory: 21284kb

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: 21252kb

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: 21244kb

input:

1 0
2 1000000000

output:

1000000000 

result:

ok 1 number(s): "1000000000"

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 21320kb

input:

3 1
1 2 3
2 1
2 2

output:

1 2 

result:

wrong answer 1st numbers differ - expected: '2', found: '1'