답안 #165432

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
165432 2019-11-27T08:31:29 Z Segtree Detecting Molecules (IOI16_molecules) C++14
컴파일 오류
0 ms 0 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<unordered_map>
#include"molecules.h"
using namespace std;
typedef long long ll;
vector<int> ans;
unordered_map<int,vector<int> >mas;
void exch(){
    for(int i=0;i<ans.size();i++){
	ll x=ans[i];
	ans[i]=mas[x].back();
	mas[x].pop_back();
    }
}
vector<int> solve(int l,int r,vector<int> w){
    int n=w.size();
    for(int i=0;i<n;i++){
	mas[w[i]].push_back(i);
    }
    sort(w.begin(),w.end());
    ll suml=0,sumr=0,x=-1;
    for(int i=0;i<n;i++){
	suml+=w[i];
	sumr+=w[n-1-i];
	if(suml<=r&&l<=sumr){
	    x=i+1;
	    break;
	}
    }
    if(x==-1)return ans;
    for(int i=0;i<x;i++)ans.push_back(w[i]);
    if(l<=suml&&suml<=r){
	exch();
	return ans;
    }
    for(int i=x-1;i>=0;i--){
	suml-=ans[i];
	suml+=w[n-x+i];
	ans[i]=w[n-x+1];
	if(l<=suml&&suml<=r){
	    exch();
	    return ans;
	}
    }
    cout<<1/0<<endl;
    return ans;
}

Compilation message

molecules.cpp: In function 'void exch()':
molecules.cpp:11:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<ans.size();i++){
                 ~^~~~~~~~~~~
molecules.cpp: In function 'std::vector<int> solve(int, int, std::vector<int>)':
molecules.cpp:47:12: warning: division by zero [-Wdiv-by-zero]
     cout<<1/0<<endl;
           ~^~
/tmp/cc1NdgUy.o: In function `main':
grader.cpp:(.text.startup+0x152): undefined reference to `find_subset(int, int, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status