Submission #223724

# Submission time Handle Problem Language Result Execution time Memory
223724 2020-04-16T08:41:12 Z bharat2002 Detecting Molecules (IOI16_molecules) C++14
Compilation error
0 ms 0 KB
/*input

*/
#include "molecules.h"
#include<bits/stdc++.h>
using namespace std;
const int N=2e5 + 100;
const int mod=1e9 + 7;
//Trace prints the name of the variable and the value.
int n;vector< pii > vals;
bool sf(pii a, pii b);
vector<int> find_subset(int l, int u, vector<int> w)
{
	vector<int> ans;
	n=w.size();
	for(int i=0;i<w.size();i++)
	{
		vals.push_back(mp(w[i], i));
	}
	sort(vals.begin(), vals.end(), sf);
	int mval=vals.back().f;
	for(auto &i:vals) i.f-=mval;
	if(mval>u) return ans;
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		sum+=vals[i-1].f;
		if(i*mval + sum>u)
		{
			if(i*mval + sum - vals[0].f<=u)
			{
				for(int j=1;j<i;j++) ans.push_back(vals[j].s);
				ans.push_back(vals.back().s);break;
			}
		}
		else if(i*mval+sum>=l)
		{
			for(int j=0;j<i;j++) ans.push_back(vals[j].s);break;
		}
	}
	return ans;
}
bool sf(pii a, pii b)
{
	return a.f>b.f;
}

/*signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int arr[]={15, 17, 16, 18};
	vector<int> vi(begin(arr), end(arr));
	find_subset(10, 20, vi);
}*/

Compilation message

molecules.cpp:10:15: error: 'pii' was not declared in this scope
 int n;vector< pii > vals;
               ^~~
molecules.cpp:10:19: error: template argument 1 is invalid
 int n;vector< pii > vals;
                   ^
molecules.cpp:10:19: error: template argument 2 is invalid
molecules.cpp:11:9: error: 'pii' was not declared in this scope
 bool sf(pii a, pii b);
         ^~~
molecules.cpp:11:16: error: 'pii' was not declared in this scope
 bool sf(pii a, pii b);
                ^~~
molecules.cpp:11:21: error: expression list treated as compound expression in initializer [-fpermissive]
 bool sf(pii a, pii b);
                     ^
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:16:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<w.size();i++)
              ~^~~~~~~~~
molecules.cpp:18:8: error: request for member 'push_back' in 'vals', which is of non-class type 'int'
   vals.push_back(mp(w[i], i));
        ^~~~~~~~~
molecules.cpp:18:18: error: 'mp' was not declared in this scope
   vals.push_back(mp(w[i], i));
                  ^~
molecules.cpp:20:12: error: request for member 'begin' in 'vals', which is of non-class type 'int'
  sort(vals.begin(), vals.end(), sf);
            ^~~~~
molecules.cpp:20:26: error: request for member 'end' in 'vals', which is of non-class type 'int'
  sort(vals.begin(), vals.end(), sf);
                          ^~~
molecules.cpp:21:16: error: request for member 'back' in 'vals', which is of non-class type 'int'
  int mval=vals.back().f;
                ^~~~
molecules.cpp:22:14: error: 'begin' was not declared in this scope
  for(auto &i:vals) i.f-=mval;
              ^~~~
molecules.cpp:22:14: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:95:0,
                 from molecules.cpp:5:
/usr/include/c++/7/valarray:1211:5: note:   'std::begin'
     begin(const valarray<_Tp>& __va)
     ^~~~~
/usr/include/c++/7/valarray:1211:5: note:   'std::begin'
molecules.cpp:22:14: error: 'end' was not declared in this scope
  for(auto &i:vals) i.f-=mval;
              ^~~~
molecules.cpp:22:14: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:95:0,
                 from molecules.cpp:5:
/usr/include/c++/7/valarray:1231:5: note:   'std::end'
     end(const valarray<_Tp>& __va)
     ^~~
/usr/include/c++/7/valarray:1231:5: note:   'std::end'
molecules.cpp:27:16: error: invalid types 'int[int]' for array subscript
   sum+=vals[i-1].f;
                ^
molecules.cpp:30:28: error: invalid types 'int[int]' for array subscript
    if(i*mval + sum - vals[0].f<=u)
                            ^
molecules.cpp:32:46: error: invalid types 'int[int]' for array subscript
     for(int j=1;j<i;j++) ans.push_back(vals[j].s);
                                              ^
molecules.cpp:33:24: error: request for member 'back' in 'vals', which is of non-class type 'int'
     ans.push_back(vals.back().s);break;
                        ^~~~
molecules.cpp:38:45: error: invalid types 'int[int]' for array subscript
    for(int j=0;j<i;j++) ans.push_back(vals[j].s);break;
                                             ^
molecules.cpp:38:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    for(int j=0;j<i;j++) ans.push_back(vals[j].s);break;
    ^~~
molecules.cpp:38:50: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
    for(int j=0;j<i;j++) ans.push_back(vals[j].s);break;
                                                  ^~~~~
molecules.cpp: At global scope:
molecules.cpp:43:9: error: redefinition of 'bool sf'
 bool sf(pii a, pii b)
         ^~~
molecules.cpp:11:6: note: 'bool sf' previously defined here
 bool sf(pii a, pii b);
      ^~
molecules.cpp:43:9: error: 'pii' was not declared in this scope
 bool sf(pii a, pii b)
         ^~~
molecules.cpp:43:16: error: 'pii' was not declared in this scope
 bool sf(pii a, pii b)
                ^~~