Submission #474700

#TimeUsernameProblemLanguageResultExecution timeMemory
474700RafaelSusDetecting Molecules (IOI16_molecules)C++14
100 / 100
86 ms6200 KiB
#include <iostream> #include <vector> #include <algorithm> std::vector<int> find_subset(int l, int r, std::vector<int> a){ std::vector<std::pair<int, int>> aa; for(int i = 0; i < a.size(); i++){ aa.push_back({a[i], i}); } std::sort(aa.begin(), aa.end()); std::sort(a.begin(), a.end()); int pl = 0; int pr = 1; long long sum = a[0]; bool ok = true; while(true){ if (pl >= a.size() && pr >= a.size()){ ok = false; break; } if (pl > pr){ ok = false; break; } if (sum >= l && sum <= r){ break; }else if (sum < l && pr < a.size()){ pr++; sum += a[pr - 1]; }else if (sum < l && pr >= a.size()) { ok = false; break; }else if (sum > r && pl < a.size()){ sum -= a[pl]; pl++; }else if (sum > r && pl >= a.size()){ ok = false; break; } } if (ok) { std::vector<int> answ; for (int i = pl; i < pr; i++) answ.push_back(aa[i].second); return answ; }else { std::vector<int> answ; return answ; } } #ifdef TEST int main(){ int l, r; unsigned int n; std::cin >> l >> r >> n; std::vector<int> a(n); for (int i = 0; i < n; i++) std::cin >> a[i]; std::vector<int> answ = find_subset(l, r, a); for (int i = 0; i < answ.size(); i++){ std::cout << answ[i] << ' '; } std::cout << '\n'; } #endif

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:6:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 |     for(int i = 0; i < a.size(); i++){
      |                    ~~^~~~~~~~~~
molecules.cpp:16:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |         if (pl >= a.size() && pr >= a.size()){
      |             ~~~^~~~~~~~~~~
molecules.cpp:16:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |         if (pl >= a.size() && pr >= a.size()){
      |                               ~~~^~~~~~~~~~~
molecules.cpp:26:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         }else if (sum < l && pr < a.size()){
      |                              ~~~^~~~~~~~~~
molecules.cpp:29:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         }else if (sum < l && pr >= a.size()) {
      |                              ~~~^~~~~~~~~~~
molecules.cpp:32:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         }else if (sum > r && pl < a.size()){
      |                              ~~~^~~~~~~~~~
molecules.cpp:35:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         }else if (sum > r && pl >= a.size()){
      |                              ~~~^~~~~~~~~~~
#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...