Submission #74162

#TimeUsernameProblemLanguageResultExecution timeMemory
74162renatsjDetecting Molecules (IOI16_molecules)C++14
46 / 100
1063 ms6948 KiB
#include<bits/stdc++.h> #include "molecules.h" struct masivs{int val;int poz;}; masivs ab[1000006]; using namespace std; int i,j,n,m,mas[1000006][2],sum; vector<int> xx; vector<int> xcur,xnew; bool c1(masivs maz,masivs liel) { if (maz.val==liel.val) { return maz.poz<liel.poz; } return maz.val<liel.val; } vector<int> find_subset(int l, int u, vector<int> w) { i=0; while (i<=u) { mas[i][0]=-1; i++; } mas[u][0]=-2; xcur.push_back(u); i=0; n=w.size(); while (i<n) { ab[i].val=w[i]; ab[i].poz=i; sum+=ab[i].val; i++; } if (sum<l) { return vector<int>(0); } sort(ab,ab+n,c1); i=n-1; while (i>=0) { for (int j:xcur) { if (j-ab[i].val>=0&&mas[j-ab[i].val][0]==-1) { //cout << i << " " << j << "\n"; mas[j-ab[i].val][0]=j; mas[j-ab[i].val][1]=ab[i].poz; if (j-ab[i].val<=u-l) { j-=ab[i].val; while (j<u) { xx.push_back(mas[j][1]); j=mas[j][0]; } return xx; } xnew.push_back(j-ab[i].val); } } for (int j:xnew) { xcur.push_back(j); } xnew.clear(); /*j=0; while (j+ab[i].val<=u) { if (mas[j+ab[i].val][0]!=-1&&mas[j][0]==-1) { mas[j][0]=j+ab[i].val; mas[j][1]=ab[i].poz; if (j<=u-l) { while (j<u) { xx.push_back(mas[j][1]); j=mas[j][0]; } return xx; } } j++; }*/ i--; } return vector<int>(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...