QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#397076#6742. Leavescoldwind902Compile Error//C++207.1kb2024-04-23 16:12:272024-04-23 16:12:27

Judging History

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

  • [2024-04-23 16:12:27]
  • 评测
  • [2024-04-23 16:12:27]
  • 提交

answer


#pragma GCC optimize(2)
#pragma GCC optimize(3)

#include <bits/stdc++.h>
#define endl '\n'
#define alls(x) x.begin(),x.end()
using namespace std;
using i64 = long long;
using PII = pair<int, int>;
const int g = 3, mod = 1e9 + 7, INF = 0x3f3f3f3f;
const int N = 510, M = 1010;

int n, m;
int val[1010], sz[1010];
PII son[1010];
vector< vector<int> > dp[1010];

bool check(vector<int>& a, vector<int>& b){
    int sz1 = a.size(), sz2 = b.size();
    int mn = min(sz1, sz2);
    for(int i = 0; i < mn; ++ i)
        if(a[i] < b[i]) return true;
        else if(a[i] > b[i]) return false;
    return sz1 < sz2;
}

void dfs(int u){
    dp[u] = vector<vector<int>>(sz[u] / 2 + 1, vector<int>());
    int lroot = son[u].first, rroot = son[u].second;
    if(lroot == 0){
        //叶节点,无论怎么变化都一样的
        dp[u][0] = {val[u]};
        return;
    }
    else {
        //递归计算左右儿子
        dfs(lroot);
        dfs(rroot);
        vector<int> res;
        //计算当前点, 不交换
        for(int i = 0; i <= sz[lroot] / 2; ++ i){//左儿子用i次
            for(int j = 0; j <= sz[rroot] / 2; ++ j){//右儿子j次
                if(i + j > m) continue;
                res.clear();
//                add(dp[lroot][i], dp[rroot][j], res);
                res.insert(res.end(), alls(dp[lroot][i]));
                res.insert(res.end(), alls(dp[rroot][j]));
                if(dp[u][i + j].empty()) dp[u][i + j] = res;
                else if(check(res, dp[u][i + j])) dp[u][i + j] = res;
            }
        }#include <bits/stdc++.h>
          #define endl '\n'
        using namespace std;
        using i64 = long long;
        using PII = pair<int, int>;
        const int g = 3, mod = 1e9 + 7, INF = 0x3f3f3f3f;
        const int N = 510, M = N << 1;

        int n, m;
        int val[M], sz[M];
        PII son[M];
        struct bi{
            vector<int> v;
            friend bi operator+ (bi a, bi b){
                for(int i : b.v) a.v.emplace_back(i);
                return a;
            }
            friend bool operator< (bi a, bi b){
                int sz1 = a.v.size(), sz2 = b.v.size();
                int mnsz = min(sz1, sz2);
                for(int i = 0; i < mnsz; ++ i){
                    if(a.v[i] < b.v[i]) return true;
                    else if(a.v[i] > b.v[i]) return false;
                }
                if(sz1 < sz2)return true;
                return false;
            }
        }dp[M][N];

        void dfs(int u){
            sz[u] = 1;
            int lroot = son[u].first, rroot = son[u].second;
            if(lroot || rroot){
                //递归计算左右儿子
                dfs(lroot);
                dfs(rroot);
                sz[u] += sz[lroot];
                sz[u] += sz[rroot];

                //计算当前点, 不交换
                for(int i = 0; i <= sz[lroot] / 2; ++ i){//左儿子用i次
                    for(int j = 0; j <= sz[rroot] / 2; ++ j){//右儿子j次
                        if(i + j > m) continue;
                        bi res = dp[lroot][i] + dp[rroot][j];
                        if(dp[u][i + j].v.empty()) dp[u][i + j] = res;
                        else if(res < dp[u][i + j]) dp[u][i + j] = res;
                    }
                }

                //交换
                for(int i = 0; i <= sz[lroot] / 2; ++ i){//左儿子用i次
                    for(int j = 0; j <= sz[rroot] / 2; ++ j){//右儿子j次
                        if(i + j >= m) continue;
                        bi res = dp[rroot][j] + dp[lroot][i];
                        if(dp[u][i + j + 1].v.empty()) dp[u][i + j + 1] = res;
                        else if(res < dp[u][i + j + 1]) dp[u][i + j + 1] = res;
                    }
                }
            }
            else{//叶节点,无论怎么变化都一样的
                for(int i = 0; i <= m; ++ i)
                    dp[u][i].v.emplace_back(val[u]);
            }
        }

        void solve() {
            cin >> n >> m;
            int op, l, r;
            for(int i = 1; i <= n; ++ i){
                cin >> op;
                if(op == 1){
                    cin >> l >> r;
                    son[i] = {l, r};
                }
                else {
                    cin >> l;//叶节点
                    val[i] = l;
                }
            }
            if(n == 1){
                cout << val[1] << endl;
                return;
            }
            dfs(1);
            bi ans = dp[1][m];
            //两次操作可以重复,这样就能抵消掉他们
            for(int i = m; i >= 0; i -= 2)
                if(dp[1][i] < ans) ans = dp[1][i];

            for(int j : ans.v)
                cout << j << ' ';
            cout << endl;
        }

        signed main() {
#ifdef ONLINE_JUDGE
#else
            freopen("902.in", "r", stdin);
            freopen("902.out", "w", stdout);
#endif
            ios::sync_with_stdio(false);
            cin.tie(0), cout.tie(0);
            int t = 1;
//    cin >> t;
            for (int i = 1; i <= t; i++) {
                solve();
            }
            return 0;
        }

        //交换
        for(int i = 0; i <= sz[lroot] / 2; ++ i){//左儿子用i次
            for(int j = 0; j <= sz[rroot] / 2; ++ j){//右儿子j次
                if(i + j >= m) continue;
                res.clear();
                res.insert(res.end(), alls(dp[rroot][j]));
                res.insert(res.end(), alls(dp[lroot][i]));
                if(dp[u][i + j + 1].empty()) dp[u][i + j + 1] = res;
                else if(check(res, dp[u][i + j + 1])) dp[u][i + j + 1] = res;
            }
        }
    }
}

int dfs_sz(int u){
    sz[u] = 1;
    if(son[u].first) sz[u] += dfs_sz(son[u].first);
    if(son[u].second) sz[u] += dfs_sz(son[u].second);
    return sz[u];
}

void solve() {
//    sz[1] = 10;
//    dp[1] = vector<vector<int>>(sz[1] / 2 + 1, vector<int>());
//    for(auto x : dp[1]){
//        if(x.empty())cout << "YES\n";
//        for(auto y : x)
//            cout << y << ' ';
//        cout << endl;
//    }
//    return;
    cin >> n >> m;
    int op, l, r;
    for(int i = 1; i <= n; ++ i){
        cin >> op;
        if(op == 1){
            cin >> l >> r;
            son[i] = {l, r};
        }
        else {
            cin >> l;//叶节点
            val[i] = l;
        }
    }
    if(n == 1){
        cout << val[1] << endl;
        return;
    }
    dfs_sz(1);
    dfs(1);
    vector<int> ans = dp[1][m];
    //两次操作可以重复,这样就能抵消掉他们
    for(int i = m; i >= 0; i -= 2)
        if(check(dp[1][i], ans)) ans = dp[1][i];

    for(int j : ans)
        cout << j << ' ';
    cout << endl;
//    cout << dp[1][m].size() << endl;
}

signed main() {
#ifdef ONLINE_JUDGE
#else
    freopen("902.in", "r", stdin);
    freopen("902.out", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t = 1;
//    cin >> t;
    for (int i = 1; i <= t; i++) {
        solve();
    }
    return 0;
}

Details

answer.code:52:10: error: stray ‘#’ in program
   52 |         }#include <bits/stdc++.h>
      |          ^
answer.code: In function ‘void dfs(int)’:
answer.code:52:20: error: ‘bits’ was not declared in this scope
   52 |         }#include <bits/stdc++.h>
      |                    ^~~~
answer.code:52:25: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
   52 |         }#include <bits/stdc++.h>
      |                         ^~~~
      |                         std
answer.code:52:11: error: ‘include’ was not declared in this scope
   52 |         }#include <bits/stdc++.h>
      |           ^~~~~~~
answer.code:54:9: error: expected primary-expression before ‘using’
   54 |         using namespace std;
      |         ^~~~~
answer.code:65:23: error: cannot define friend function ‘operator+’ in a local class definition
   65 |             friend bi operator+ (bi a, bi b){
      |                       ^~~~~~~~
answer.code:65:23: error: ‘dfs(int)::bi dfs(int)::bi::operator+(dfs(int)::bi, dfs(int)::bi)’ must have either zero or one argument
answer.code:69:25: error: cannot define friend function ‘operator<’ in a local class definition
   69 |             friend bool operator< (bi a, bi b){
      |                         ^~~~~~~~
answer.code:69:25: error: ‘bool dfs(int)::bi::operator<(dfs(int)::bi, dfs(int)::bi)’ must have exactly one argument
answer.code:81:24: error: a function-definition is not allowed here before ‘{’ token
   81 |         void dfs(int u){
      |                        ^
answer.code:117:22: error: a function-definition is not allowed here before ‘{’ token
  117 |         void solve() {
      |                      ^
answer.code:146:20: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
  146 |         signed main() {
      |                    ^~
answer.code:146:20: note: remove parentheses to default-initialize a variable
  146 |         signed main() {
      |                    ^~
      |                    --
answer.code:146:20: note: or replace parentheses with braces to value-initialize a variable
answer.code:146:23: error: a function-definition is not allowed here before ‘{’ token
  146 |         signed main() {
      |                       ^
answer.code:7:19: error: ‘struct dfs(int)::bi’ has no member named ‘begin’
    7 | #define alls(x) x.begin(),x.end()
      |                   ^~~~~
answer.code:167:39: note: in expansion of macro ‘alls’
  167 |                 res.insert(res.end(), alls(dp[rroot][j]));
      |                                       ^~~~
answer.code:7:29: error: ‘struct dfs(int)::bi’ has no member named ‘end’
    7 | #define alls(x) x.begin(),x.end()
      |                             ^~~
answer.code:167:39: note: in expansion of macro ‘alls’
  167 |                 res.insert(res.end(), alls(dp[rroot][j]));
      |                                       ^~~~
answer.code:7:19: error: ‘struct dfs(int)::bi’ has no member named ‘begin’
    7 | #define alls(x) x.begin(),x.end()
      |                   ^~~~~
answer.code:168:39: note: in expansion of macro ‘alls’
  168 |                 res.insert(res.end(), alls(dp[lroot][i]));
      |                                       ^~~~
answer.code:7:29: error: ‘struct dfs(int)::bi’ has no member named ‘end’
    7 | #define alls(x) x.begin(),x.end()
      |                             ^~~
answer.code:168:39: note: in expansion of macro ‘alls’
  168 |                 res.insert(res.end(), alls(dp[lroot][i]));
      |                                       ^~~~
answer.code:169:37: error: ‘struct dfs(int)::bi’ has no member named ‘empty’
  169 |                 if(dp[u][i + j + 1].empty()) dp[u][i + j + 1] = res;
      |                                     ^~~~~
answer.code:169:65: error: no match for ‘operator=’ (operand types are ‘dfs(int)::bi’ and ‘std::vector<int>’)
  169 |                 if(dp[u][i + j + 1].empty()) dp[u][i + j + 1] = res;
      |                                                                 ^~~
answer.code:63:16: note: candidate: ‘constexpr dfs(int)::bi& dfs(int)::bi::operator=(const dfs(int)::bi&)’
   63 |         struct bi{
      |                ^~
answer.code:63:16: note:   no known conversion for argument 1 from ‘std::vector<int>’ to ‘const dfs(int)::bi&’
answer.code:63:16: note: candidate: ‘constexpr dfs(int)::bi& dfs(int)::bi::operator=(dfs(int)::bi&&)’
answer.code:63:16: note:   no known conversion for argument 1 from ‘std::vector<int>’ to ‘dfs(int)::bi&&’
answer.code:170:51: error: invalid initialization of reference of type ‘std::vector<int>&’ from expression of type ‘dfs(int)::bi’
  170 |                 else if(check(res, dp[u][i + j + 1])) dp[u][i + j + 1] = res;
      |                                    ~~~~~~~~~~~~~~~^
answer.code:19:41: note: in passing argument 2 of ‘bool check(std::vector<int>&, std::vector<int>&)’
   19 | bool check(vector<int>& a, vector<int>& b){
      |                            ~~~~~~~~~~~~~^
answer.code:17...