QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#397010#6742. LeavesskulkerWA 47ms44548kbC++202.2kb2024-04-23 15:27:282024-04-23 15:27:29

Judging History

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

  • [2024-04-23 15:27:29]
  • 评测
  • 测评结果:WA
  • 用时:47ms
  • 内存:44548kb
  • [2024-04-23 15:27:28]
  • 提交

answer

#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
using namespace std;
int n,m;
string dp[1010][501];
string temp[1010][501];
//vector<int> len[1100][510];

int lf[1010];
int siz[1100];

vector<int> nex[1100];

void dfs(int now){
    siz[now]=1;
    lf[now]=0;
    if(nex[now].size()==0){
        lf[now]=1;
        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;
                temp[now][i+j]=temp[l][i]+temp[r][j];
            }
            else {
                if(dp[now][i+j]>s2) {
                    dp[now][i+j]=s2;
                    temp[now][i+j]=temp[l][i]+temp[r][j];
                }
            }
        }
    }
    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;
                temp[now][i+j+1]=temp[l][i]+temp[r][j];
            }
            else {
                if(dp[now][i+j+1]>s2) {
                    dp[now][i+j+1]=s2;
                    temp[now][i+j+1]=temp[l][i]+temp[r][j];
                }
            }
        }
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    int u,v,w;
    int opt;
    for(int i=1;i<=n;i++){
        cin>>opt;
        if(opt==1){
            cin>>u>>v;
            nex[i].push_back(u);
            nex[i].push_back(v);
        }
        else {
            cin>>dp[i][0];
            temp[i][0]=dp[i][0]+" ";
        }
    }
    dfs(1);
    string ans=dp[1][m];
    int pos=m;
    for(int i=m-2;i>=0;i-=2){
        if(ans>dp[1][i]) {
            ans=dp[1][i];
            pos=i;
        }
    }
    cout<<temp[1][pos];
}

详细

Test #1:

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

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: 5ms
memory: 35148kb

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

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

input:

1 0
2 1000000000

output:

1000000000 

result:

ok 1 number(s): "1000000000"

Test #5:

score: 0
Accepted
time: 3ms
memory: 35196kb

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

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: 47ms
memory: 44548kb

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:

125712955 763875883 763875883 763875883 763875883 763875883 763875883 763875883 277558689 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 763875883 ...

result:

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