QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#396970#6742. LeavesskulkerWA 7ms34728kbC++143.2kb2024-04-23 15:04:212024-04-23 15:04:21

Judging History

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

  • [2024-04-23 15:04:21]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:34728kb
  • [2024-04-23 15:04:21]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
using namespace std;
int n,m;
string dp[1100][510];
vector<int> len[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];
        len[now][0].push_back(val[now].size());
        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;
                for(int k=0;k<len[l][i].size();k++){
                    len[now][i+j].push_back(len[l][i][k]);
                }
                for(int k=0;k<len[r][j].size();k++){
                    len[now][i+j].push_back(len[r][j][k]);
                }
            }
            else {
                if(dp[now][i+j]>s2) {
                    dp[now][i+j]=s2;
                    for(int k=0;k<len[l][i].size();k++){
                        len[now][i+j].push_back(len[l][i][k]);
                    }
                    for(int k=0;k<len[r][j].size();k++){
                        len[now][i+j].push_back(len[r][j][k]);
                    }
                }
            }
        }
    }
    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;
                for(int k=0;k<len[l][i].size();k++){
                    len[now][i+j+1].push_back(len[l][i][k]);
                }
                for(int k=0;k<len[r][j].size();k++){
                    len[now][i+j+1].push_back(len[r][j][k]);
                }
            }
            else {
                if(dp[now][i+j+1]>s2) {
                    dp[now][i+j+1]=s2;
                    for(int k=0;k<len[l][i].size();k++){
                        len[now][i+j+1].push_back(len[l][i][k]);
                    }
                    for(int k=0;k<len[r][j].size();k++){
                        len[now][i+j+1].push_back(len[r][j][k]);
                    }
                }
            }
//            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][m];
    int k=len[1][m][0];
    int pos=m;
    int cnt=0;
    for(int i=0;i<ans.size();i++){
        cout<<ans[i];
        k--;
        if(k==0){
            cout<<" ";
            cnt++;
            k=len[1][pos][cnt];
        }
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 7ms
memory: 34436kb

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

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: 6ms
memory: 34728kb

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

input:

1 0
2 1000000000

output:

1000000000 

result:

ok 1 number(s): "1000000000"

Test #5:

score: 0
Accepted
time: 6ms
memory: 34432kb

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: 3ms
memory: 34412kb

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'