Submission #484487

#TimeUsernameProblemLanguageResultExecution timeMemory
484487_BodyDetecting Molecules (IOI16_molecules)C++17
0 / 100
1 ms292 KiB
#include "molecules.h" //#include"grader.cpp" #include<bits/stdc++.h> using namespace std; vector<int> find_subset(int l, int u, std::vector<int> w) { vector<int>res; vector<pair<long long,int>>arr; int n=w.size(); for(int i=0;i<n;i++) { if(w[i]>=l&&w[i]<=u) { res.push_back(i+1); return res; } // if(w[i]<l) // { arr.push_back({w[i],i}); // } } sort(arr.begin(),arr.end()); long long sum=0; ///int l=0; deque<int>deq; bool is=false; for(int i=0;i<arr.size();i++) { deq.push_back(arr[i].second); sum+=arr[i].first; if(sum>=l&&sum<=u) { is=true; break; } if(sum>u) { while(sum>u) { sum-=(w[deq.front()]); deq.pop_front(); } if(sum<=u&&sum>=l) { is=true; break; } } } if(!is) { return (vector<int>{}); } long long tmp=0; for(auto x:deq) res.push_back((x+1)); for(int rr:res) tmp+=(w[rr-1]); if(tmp>u) { int x=1/0; } if(tmp!=sum) int x=1/0; return res; } /* 4 15 17 6 8 8 7 */

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:26:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i=0;i<arr.size();i++)
      |                 ~^~~~~~~~~~~
molecules.cpp:54:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   54 |     for(auto x:deq)
      |     ^~~
molecules.cpp:56:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   56 |         for(int rr:res)
      |         ^~~
molecules.cpp:60:20: warning: division by zero [-Wdiv-by-zero]
   60 |             int x=1/0;
      |                   ~^~
molecules.cpp:60:17: warning: unused variable 'x' [-Wunused-variable]
   60 |             int x=1/0;
      |                 ^
molecules.cpp:63:20: warning: division by zero [-Wdiv-by-zero]
   63 |             int x=1/0;
      |                   ~^~
molecules.cpp:63:17: warning: unused variable 'x' [-Wunused-variable]
   63 |             int x=1/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...