답안 #223738

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223738 2020-04-16T09:18:14 Z bharat2002 Detecting Molecules (IOI16_molecules) C++14
컴파일 오류
0 ms 0 KB
/*input
10 20
4
15 17 16 18
*/
#include "molecules.h"
#include<bits/stdc++.h>
using namespace std;
const int N=2e5 + 100;
#define int long long
const int mod=1e9 + 7;
#define pii pair<int, int>
#define mp make_pair
#define f first
#define s second
int n;vector< pii > vals;
bool sf(pii a, pii b);int pref[N];
vector<int> ans;int L, U;
void check(int num)
{
	if(pref[num-1]<=U)
	{
		for(int i=0;i<num;i++) ans.push_back(vals[i].s);return;
	}
	for(int i=num;i<n;i++)
	{
		if(pref[i]-pref[i-num]>=L&&pref[i]-pref[i-num]<=U)
		{
			for(int j=i-num+1;j<=i;j++) ans.push_back(vals[j].s);return;
		}
	}
}
vector<int> find_subset(int l, int u, vector<int> w)
{
	vals.clear();L=l;U=u;
	n=w.size();
	for(int i=0;i<w.size();i++)
	{
		vals.push_back(mp(w[i], i));
	}
	sort(vals.begin(), vals.end(), sf);
		pref[0]=0;;
	for(int i=0;i<vals.size();i++)
	{
		pref[i]=vals[i].f;
		if(i>0) pref[i]+=pref[i-1];
	}

	for(int i=1;i<=n;i++)
	{
		if(i==n)
		{
			if(pref[n-1]>=l&&pref[n-1]<=u)
			{
				for(int i=0;i<n;i++) ans.push_back(vals[i].s);
			}
			break;
		}

		int maxsum=pref[i-1], minsum=pref[n-1] - pref[n-i-1];
//		cout<<maxsum<<" "<<minsum<<endl;
		if(minsum>u) break;
		if(maxsum<l) continue;check(i);if(!ans.empty()) break;
	}
	return ans;
}
bool sf(pii a, pii b)
{
	return a.f>b.f;
}
/*signed main()
{
	int l, u;cin>>l>>u;
	int n;cin>>n;vector<int> vs;
	for(int i=1;i<=n;i++)
	{
		int v;cin>>v;vs.push_back(v);
	}
	find_subset(l, u, vs);
}*/

Compilation message

molecules.cpp: In function 'void check(long long int)':
molecules.cpp:23:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   for(int i=0;i<num;i++) ans.push_back(vals[i].s);return;
   ^~~
molecules.cpp:23:51: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   for(int i=0;i<num;i++) ans.push_back(vals[i].s);return;
                                                   ^~~~~~
molecules.cpp:29:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    for(int j=i-num+1;j<=i;j++) ans.push_back(vals[j].s);return;
    ^~~
molecules.cpp:29:57: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
    for(int j=i-num+1;j<=i;j++) ans.push_back(vals[j].s);return;
                                                         ^~~~~~
molecules.cpp: In function 'std::vector<long long int> find_subset(long long int, long long int, std::vector<long long int>)':
molecules.cpp:37:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<w.size();i++)
              ~^~~~~~~~~
molecules.cpp:43:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<vals.size();i++)
              ~^~~~~~~~~~~~
molecules.cpp:63:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   if(maxsum<l) continue;check(i);if(!ans.empty()) break;
   ^~
molecules.cpp:63:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   if(maxsum<l) continue;check(i);if(!ans.empty()) break;
                         ^~~~~
/tmp/ccVK3h0X.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