답안 #299056

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
299056 2020-09-14T12:50:56 Z azatega Detecting Molecules (IOI16_molecules) C++11
0 / 100
1 ms 324 KB
#include "molecules.h"
#include <vector>
#include <algorithm>
#include <iostream>

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(); x++)
    			res.push_back(new_w[x].second);
    		return res;
    	}

    	suff_sum[i] = currsum;
    }

    suff_sum.push_back(0);

    for(int i = 0; i < suff_sum.size(); i++)
    	cout << suff_sum[i] << endl;

    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 = 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;
}

/*int main(){
	int n, l, u;
	vector<int> niz;
	cin >> n >> l >> u;
	
	niz.resize(n);
	for(int i = 0; i < n; i++)
		cin >> niz[i];
	find_subset(l, u, niz);
}*/

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:12:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |  for(int i = 0; i < w.size(); i++)
      |                 ~~^~~~~~~~~~
molecules.cpp:26: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]
   26 |       for(int x = i; x < new_w.size(); x++)
      |                      ~~^~~~~~~~~~~~~~
molecules.cpp:36:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i = 0; i < suff_sum.size(); i++)
      |                    ~~^~~~~~~~~~~~~~~~~
molecules.cpp:41: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]
   41 |     for(int i = 0; i < new_w.size(); i++){
      |                    ~~^~~~~~~~~~~~~~
molecules.cpp:55: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]
   55 |        for(int x = mid; x < new_w.size(); x++)
      |                         ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Secret is incorrect!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 324 KB Secret is incorrect!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Secret is incorrect!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Secret is incorrect!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Secret is incorrect!
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Secret is incorrect!
2 Halted 0 ms 0 KB -