Submission #299038

# Submission time Handle Problem Language Result Execution time Memory
299038 2020-09-14T12:36:30 Z azatega Detecting Molecules (IOI16_molecules) C++11
0 / 100
70 ms 65540 KB
#include "molecules.h"
#include <vector>
#include <algorithm>

using namespace std;

#define ll long long

vector<int> find_subset(int l, int u, vector<int> w) {
	vector<pair<ll, int>> new_w;
	for(int i = 0; i < w.size(); i++)
		new_w.push_back({w[i], i});

	sort(new_w.begin(), new_w.end());

    vector<ll> suff_sum;
    suff_sum.resize(new_w.size());
    ll currsum = 0;

    for(int i = new_w.size()-1; i >= 0; i--){
    	currsum += new_w[i].first;
    	if(currsum >= l && currsum <= u){
    		// found it!
    		vector<int> res;
    		for(int x = i; x < new_w.size(); i++)
    			res.push_back(new_w[x].second);
    		return res;
    	}

    	suff_sum[i] = currsum;
    }

    bool found = false;
    currsum = 0;

    for(int i = 0; i < new_w.size(); i++){
    	currsum += new_w[i].first;

    	int l = i+1;
    	int r = new_w.size();
    	while(l <= r){
    		int mid = (l+r)/2;

    		int new_val = 0;
    		if(mid < new_w.size())
    			new_val = suff_sum[mid];

    		if(new_val+currsum >= l && new_val+currsum <= r){
    			// found it
    			vector<int> res;
    			for(int x = 0; x <= i; x++)
    				res.push_back(new_w[x].second);
    			for(int x = mid; x < new_w.size(); x++)
    				res.push_back(new_w[x].second);
    			
    			return res;
    		}else if(new_val + currsum < l){
    			r = mid - 1;
    		}else if(new_val + currsum > r){
    			l = mid + 1;
    		}
    	}
    }

    vector<int> bl;
    return bl;
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:11:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |  for(int i = 0; i < w.size(); i++)
      |                 ~~^~~~~~~~~~
molecules.cpp:25:24: 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]
   25 |       for(int x = i; x < new_w.size(); i++)
      |                      ~~^~~~~~~~~~~~~~
molecules.cpp:36:22: 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]
   36 |     for(int i = 0; i < new_w.size(); i++){
      |                    ~~^~~~~~~~~~~~~~
molecules.cpp:45:14: 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]
   45 |       if(mid < new_w.size())
      |          ~~~~^~~~~~~~~~~~~~
molecules.cpp:53:27: 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]
   53 |        for(int x = mid; x < new_w.size(); x++)
      |                         ~~^~~~~~~~~~~~~~
molecules.cpp:33:10: warning: unused variable 'found' [-Wunused-variable]
   33 |     bool found = false;
      |          ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB OK (n = 1, answer = NO)
2 Correct 0 ms 256 KB OK (n = 1, answer = NO)
3 Runtime error 70 ms 65540 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB Contestant can not find answer, jury can
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB OK (n = 1, answer = NO)
2 Correct 0 ms 256 KB OK (n = 1, answer = NO)
3 Runtime error 70 ms 65540 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB OK (n = 1, answer = NO)
2 Correct 0 ms 256 KB OK (n = 1, answer = NO)
3 Runtime error 70 ms 65540 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB OK (n = 1, answer = NO)
2 Correct 0 ms 256 KB OK (n = 1, answer = NO)
3 Runtime error 70 ms 65540 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB OK (n = 1, answer = NO)
2 Correct 0 ms 256 KB OK (n = 1, answer = NO)
3 Runtime error 70 ms 65540 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -