Submission #785065

#TimeUsernameProblemLanguageResultExecution timeMemory
785065LyricallyDetecting Molecules (IOI16_molecules)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
int read(){int x;scanf("%d",&x);return x;}
void print(int x){printf("%d\n",x);}
void file(string s)
{
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}
const int mod=998244353;
int find_subset(int l,int r,int w[],int n,int res[])
{
	vector<pii> v;
	rep(i,n)
	{
		v.pb({w[i],i});
	}
	sort(v.begin(),v.end());
	long long tot=0;
	rep(i,n)
	{
		if(tot+v[i].first>r)
		{
			if(i==n-1){return 0;}
			//cout<<i<<" "<<v[0].first<<" "<<v[i].first<<" "<<v.back().first<<endl;
			long long cur=tot-v[0].first+v[i].first;
			if(cur>=l&&cur<=r)
			{
				for(int j=0;j<i;j++)
				{
					res[j]=v[j+1].second+1;
				}
				sort(res,res+i);
				return i;
			}
			cur+=v.back().first;
			if(cur>=l&&cur<=r)
			{
				for(int j=0;j<i;j++)
				{
					res[j]=v[j+1].second+1;
				}
				res[i]=v.back().second+1;
				sort(res,res+i+1);
				return i+1;
			}
		}
		else if(tot+v[i].first>=l&&tot+v[i].first<=r)
		{
			//6,7,8,8
			for(int j=0;j<=i;j++)
			{
				res[j]=v[j].second+1;
			}
			sort(res,res+i+1);
			return i+1;
		}
		tot+=v[i].first;
	}
	return 0;
}

Compilation message (stderr)

molecules.cpp: In function 'int read()':
molecules.cpp:7:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | int read(){int x;scanf("%d",&x);return x;}
      |                  ~~~~~^~~~~~~~~
molecules.cpp: In function 'void file(std::string)':
molecules.cpp:11:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  freopen((s+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
molecules.cpp:12:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  freopen((s+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccshNYU8.o: in function `main':
grader.cpp:(.text.startup+0x18d): undefined reference to `find_subset(int, int, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status