답안 #314611

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
314611 2020-10-20T12:58:21 Z Dymo Detecting Molecules (IOI16_molecules) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.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:18:37: error: expected ',' or '...' before 'w'
   18 | 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:20:20: error: 'n' was not declared in this scope
   20 |     for (int i=0;i<n;i++)
      |                    ^
molecules.cpp:22:17: error: 'w' was not declared in this scope
   22 |         a[i].ff=w[i];
      |                 ^
molecules.cpp:25:14: error: 'n' was not declared in this scope
   25 |     sort(a,a+n);
      |              ^
molecules.cpp:38:17: error: 'result' was not declared in this scope
   38 |                 result[j]=a[j].ss;
      |                 ^~~~~~
molecules.cpp:40:18: error: 'result' was not declared in this scope
   40 |             sort(result,result+m);
      |                  ^~~~~~
molecules.cpp:60:21: error: 'result' was not declared in this scope
   60 |                     result[j]=a[t1].ss;
      |                     ^~~~~~
molecules.cpp:65:21: error: 'result' was not declared in this scope
   65 |                     result[j]=a[t2].ss;
      |                     ^~~~~~
molecules.cpp:70:19: error: 'result' was not declared in this scope
   70 |              sort(result,result+m);
      |                   ^~~~~~