Submission #727479

#TimeUsernameProblemLanguageResultExecution timeMemory
727479josiftepeDetecting Molecules (IOI16_molecules)C++14
Compilation error
0 ms0 KiB
//#include <bits/stdc++.h> //#include "molecules.h" using namespace std; struct node { int idx, at, weight; node () {} node(int _at, int _weight, int _idx){ idx = _idx; at = _at; weight = _weight; } bool operator != (const node &tmp) { if(idx == tmp.idx and at == tmp.at and weight == tmp.weight) { return false; } return true; } }; int dp[10005][1005]; node backtrac[10005][1005]; vector<int> v; int rec(int at, int weight) { if(weight == 0) { backtrac[at][weight] = node(-1, -1, -1); return 1; } if(at == -1) { return 0; } if(dp[at][weight] != -1) { return dp[at][weight]; } int r1 = 0, r2 = 0; if(weight - v[at] >= 0) { r1 = rec(at - 1, weight - v[at]); } r2 = rec(at - 1, weight); if(r1 > r2) { backtrac[at][weight] = node(at - 1, weight - v[at], at); } else { backtrac[at][weight] = node(at - 1, weight, -1); } return dp[at][weight] = max(r1, r2); } vector<int> find_subset(int l, int u, vector<int> w) { v =w; int n = w.size(); int W = -1; memset(dp, -1, sizeof dp); for(int i = l; i <= u; i++) { if(rec(n - 1, i) == 1) { W = i; break; } } if(W == -1) { return {}; } node at; vector<pair<int, int> > res; int tmp = 0; vector<int> R; // cout << backtrac[n - 1][W].at << " " << backtrac[n - 1][W].weight << endl; for(at = node(n - 1, W, n - 1); at.at != -1; at = backtrac[backtrac[at.at][at.weight].at][backtrac[at.at][at.weight].weight]) { //cout << at.at << " " << at.weight << " " << at.idx << endl; if(at.idx != -1) { R.push_back(at.idx + 1); // cout << at.idx + 1 << endl; } } return R; }

Compilation message (stderr)

molecules.cpp:22:1: error: 'vector' does not name a type
   22 | vector<int> v;
      | ^~~~~~
molecules.cpp: In function 'int rec(int, int)':
molecules.cpp:35:17: error: 'v' was not declared in this scope
   35 |     if(weight - v[at] >= 0) {
      |                 ^
molecules.cpp:41:54: error: 'v' was not declared in this scope
   41 |         backtrac[at][weight] = node(at - 1, weight - v[at], at);
      |                                                      ^
molecules.cpp:47:29: error: 'max' was not declared in this scope
   47 |     return dp[at][weight] = max(r1, r2);
      |                             ^~~
molecules.cpp: At global scope:
molecules.cpp:49:1: error: 'vector' does not name a type
   49 | vector<int> find_subset(int l, int u, vector<int> w) {
      | ^~~~~~