Submission #484485

#TimeUsernameProblemLanguageResultExecution timeMemory
484485_BodyDetecting Molecules (IOI16_molecules)C++17
0 / 100
1 ms204 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) { vector<int>em(0); return em; } 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:55:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   55 |     for(auto x:deq)
      |     ^~~
molecules.cpp:57:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   57 |         for(int rr:res)
      |         ^~~
molecules.cpp:61:20: warning: division by zero [-Wdiv-by-zero]
   61 |             int x=1/0;
      |                   ~^~
molecules.cpp:61:17: warning: unused variable 'x' [-Wunused-variable]
   61 |             int x=1/0;
      |                 ^
molecules.cpp:64:20: warning: division by zero [-Wdiv-by-zero]
   64 |             int x=1/0;
      |                   ~^~
molecules.cpp:64:17: warning: unused variable 'x' [-Wunused-variable]
   64 |             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...