Submission #314613

# Submission time Handle Problem Language Result Execution time Memory
314613 2020-10-20T12:59:27 Z Dymo Detecting Molecules (IOI16_molecules) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include "molecules.h"
using namespace std;


#define pb	push_back
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define endl "\n"
const ll maxn=4e5+50;
const ll mod =1e9+7;
const ll base=517;
pll a[maxn];
ll f[maxn];

int find_subset(int l, int u, int[] w, int n, int[] result)
{
    for (int i=0;i<n;i++)
    {
        a[i].ff=w[i];
        a[i].ss=i;
    }
    sort(a,a+n);
    for (int i=0;i<n;i++)
    {
        if (i) f[i]=f[i-1]+a[i].ff;
        else f[i]=a[i].ff;
    }
    for (int i=1;i<=n;i++)
    {
         if (f[i-1]>=l&&f[i-1]<=u)
         {
             ll m=i;
            for (int j=0;j<m;j++)
            {
                result[j]=a[j].ss;
            }
            sort(result,result+m);
            return m;
         }
         else if (f[i-1]<l&&i!=n&&f[n-1]-f[n-1-i]>=l)
         {
             ll t1=i-1;
             ll t2=n;
             ll ans=f[i-1];
             while (t1>=0&&ans<l)
             {
                  ans-=a[t1].ff;
                  t1--;
                  t2--;
                  ans+=a[t2].ff;
             }
             ll m=i;
             for (int j=0;j<m;j++)
             {
                if (t1>=0)
                {
                    result[j]=a[t1].ss;
                    t1--;
                }
                else if (t2<n)
                {
                    result[j]=a[t2].ss;
                    t2++;

                }
             }
             sort(result,result+m);
            return m;


         }
    }
    return 0;
}
/*int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if (fopen("GIDDY.inp", "r"))
    {
        freopen("GIDDY.inp", "r", stdin);
        freopen("GIDDY.out", "w", stdout) ;
    }

}*/

Compilation message

molecules.cpp:19:37: error: expected ',' or '...' before 'w'
   19 | int find_subset(int l, int u, int[] w, int n, int[] result)
      |                                     ^
molecules.cpp: In function 'int find_subset(int, int, int*)':
molecules.cpp:21:20: error: 'n' was not declared in this scope
   21 |     for (int i=0;i<n;i++)
      |                    ^
molecules.cpp:23:17: error: 'w' was not declared in this scope
   23 |         a[i].ff=w[i];
      |                 ^
molecules.cpp:26:14: error: 'n' was not declared in this scope
   26 |     sort(a,a+n);
      |              ^
molecules.cpp:39:17: error: 'result' was not declared in this scope
   39 |                 result[j]=a[j].ss;
      |                 ^~~~~~
molecules.cpp:41:18: error: 'result' was not declared in this scope
   41 |             sort(result,result+m);
      |                  ^~~~~~
molecules.cpp:61:21: error: 'result' was not declared in this scope
   61 |                     result[j]=a[t1].ss;
      |                     ^~~~~~
molecules.cpp:66:21: error: 'result' was not declared in this scope
   66 |                     result[j]=a[t2].ss;
      |                     ^~~~~~
molecules.cpp:71:19: error: 'result' was not declared in this scope
   71 |              sort(result,result+m);
      |                   ^~~~~~