Submission #132457

#TimeUsernameProblemLanguageResultExecution timeMemory
132457bogdan10bosDetecting Molecules (IOI16_molecules)C++14
100 / 100
68 ms6512 KiB
/// inapt #include "molecules.h" #include <bits/stdc++.h> using namespace std; typedef long long LL; vector<int> find_subset(int l, int u, vector<int> w) { vector<int> ord; for(int i = 0; i < w.size(); i++) ord.push_back(i); sort(ord.begin(), ord.end(), [&](int a, int b) { return w[a] < w[b]; } ); vector<LL> sum(w.size()); LL s = 0; for(int i = 0; i < w.size(); i++) { s += w[ ord[i] ]; sum[i] = s; } vector<int> ans; if(l <= s && s <= u) { sort(ord.begin(), ord.end()); return ord; } int L = l, R = u, N = w.size(); for(int i = 0; i < w.size(); i++) { if(sum[i] > R) break; //if(s - sum[N - i - 2] < L) continue; int lgt = i + 1; int st = 0, dr = N - lgt; while(st <= dr) { int mij = st + (dr - st) / 2; LL ss = sum[mij + lgt - 1]; if(mij > 0) ss -= sum[mij - 1]; if(ss <= R) { if(ss >= L) { int j = mij; for(int k = j; k < j + lgt; k++) ans.push_back(ord[k]); sort(ans.begin(), ans.end()); return ans; } st = mij + 1; } else dr = mij - 1; } } return ans; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:12:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < w.size(); i++) ord.push_back(i);
                 ~~^~~~~~~~~~
molecules.cpp:18:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < w.size(); i++)
                 ~~^~~~~~~~~~
molecules.cpp:32:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < w.size(); i++)
                 ~~^~~~~~~~~~
#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...