Submission #727443

#TimeUsernameProblemLanguageResultExecution timeMemory
727443josiftepeDetecting Molecules (IOI16_molecules)C++14
0 / 100
61 ms65536 KiB
#include <bits/stdc++.h> #include "molecules.h" using namespace std; int dp[10005][1005]; pair<int, int> backtrac[10005][1005]; vector<int> v; int rec(int at, int weight) { if(weight == 0) { backtrac[at][weight] = make_pair(-1, 1); return 1; } if(at == -1) { return 0; } if(dp[at][weight] != -1) { return dp[at][weight]; } int result = 0; 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] = make_pair(at - 1, weight - v[at]); } else { backtrac[at][weight] = make_pair(at - 1, weight); } 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 {}; } pair<int, int> at; vector<pair<int, int> > res; int tmp = 0; for(at = make_pair(n - 1, W); at != make_pair(-1, -1); at = backtrac[backtrac[at.first][at.second].first][backtrac[at.first][at.second].second]) { res.push_back(make_pair(at.first, at.second)); } vector<int> R; for(int i = 0; i< (int) res.size(); i++) { if(i + 1 < (int) res.size() and res[i].second != res[i + 1].second) { R.push_back(res[i].first + 1); // cout << res[i].first + 1 << endl; } } return R; }

Compilation message (stderr)

molecules.cpp: In function 'int rec(int, int)':
molecules.cpp:20:9: warning: unused variable 'result' [-Wunused-variable]
   20 |     int result = 0;
      |         ^~~~~~
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:51:9: warning: unused variable 'tmp' [-Wunused-variable]
   51 |     int tmp = 0;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...