QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#249412#6742. LeavesRobeZHWA 0ms3820kbC++232.1kb2023-11-12 06:10:592023-11-12 06:10:59

Judging History

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

  • [2023-11-12 06:10:59]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3820kb
  • [2023-11-12 06:10:59]
  • 提交

answer

#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
#define FR(i,n) for(int i=0;i<n;++i)
#define eb emplace_back
#define st first
#define nd second
#define x1 fxxkcjb
#define y1 fxxkyzc
#define x2 fxxkzzy
#define y2 fxxknitit
using namespace std;
namespace R=ranges;
template<typename T>
using func=function<T>;
using ll=long long;
using ld=long double;
using pii=pair<int,int>;
const int mod=998244353,LIM=1e4,inf=1e9+7;
const vector<vector<int>> d={{1,0},{0,1},{-1,0},{0,-1}};
int Cas;
void sol(){
    int n,m;cin>>n>>m;
    vector<int>a(n);vector<pii>c(n);
    vector<vector<pii>>dp(n);
    FR(i,n){
        int typ;cin>>typ;
        if(typ==1){
            cin>>c[i].st>>c[i].nd;
            --c[i].st,--c[i].nd;
        }
        else cin>>a[i];
    }
    func<void(int,int,vector<int>&)>get=[&](int x,int k,vector<int>&ret){
        if(a[x]>0){ret.eb(a[x]);return;}
        if((dp[x][k].st+dp[x][k].nd+k)%2==0){
            get(c[x].st,dp[x][k].st,ret);
            get(c[x].nd,dp[x][k].nd,ret);
        }else{
            get(c[x].nd,dp[x][k].nd,ret);
            get(c[x].st,dp[x][k].st,ret);
        }
    };
    for(int cur=n-1;~cur;--cur)if(a[cur]==0){
        auto[l,r]=c[cur];
        dp[cur].assign(dp[l].size()+dp[r].size(),{0,0});
        vector<vector<int>>mi(dp[l].size()+dp[r].size(),{inf});
        FR(i,dp[l].size())FR(j,dp[r].size()){
            vector<int>temp;
            get(l,i,temp);get(r,j,temp);
            if(temp<mi[i+j])swap(temp,mi[i+j]),dp[cur][i+j]={i,j};
            temp.clear();
            get(r,j,temp);get(l,i,temp);
            if(temp<mi[i+j+1])swap(temp,mi[i+j+1]),dp[cur][i+j+1]={i,j};
        }
        FR(i,dp[cur].size())if(i>=2&&mi[i]>mi[i-2]){
            swap(mi[i],mi[i-2]);
            dp[i]=dp[i-2];
        }
    }else dp[cur].eb(-1,-1);
    vector<int>ans;
    get(0,m,ans);
    for(int&x:ans)cout<<x<<" ";
    cout<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    sol();
    return 0;
}
/*
3 2
.*.
.*.
...

3 3
.*.
.*.
...
*/

詳細信息

Test #1:

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

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

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

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

input:

1 0
2 1000000000

output:

1000000000 

result:

ok 1 number(s): "1000000000"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3620kb

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: 0ms
memory: 3792kb

input:

7 2
1 2 3
1 4 5
1 6 7
2 1
2 2
2 3
2 4

output:

2 1 3 4 

result:

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