Submission #132452

#TimeUsernameProblemLanguageResultExecution timeMemory
132452bogdan10bosDetecting Molecules (IOI16_molecules)C++14
9 / 100
3 ms424 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; for(int j = 0; j + lgt < N; j++) { LL ss = sum[j + lgt - 1]; if(j > 0) ss -= sum[j - 1]; if(L <= ss && ss <= R) { for(int k = j; k < j + lgt; k++) ans.push_back(ord[k]); sort(ans.begin(), ans.end()); return ans; } } } 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...