Submission #392416

#TimeUsernameProblemLanguageResultExecution timeMemory
392416usachevd0Detecting Molecules (IOI16_molecules)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using ld = long double;
template<typename T1, typename T2> bool chkmin(T1& x, T2 y) {
  return y < x ? (x = y, true) : false;
}
template<typename T1, typename T2> bool chkmax(T1& x, T2 y) {
  return y > x ? (x = y, true) : false;
}
void debug_out() {
  cerr << endl;
}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) {
  cerr << ' ' << A;
  debug_out(B...);
}
template<typename T> void mdebug_out(T* a, int n) {
  for (int i = 0; i < n; ++i) {
    cerr << a[i] << ' ';
  }
  cerr << endl;
}
#ifdef DEBUG
  #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
  #define mdebug(a, n) cerr << #a << ": ", mdebug_out(a, n)
#else
  #define debug(...) 1337
  #define mdebug(a, n) 1337
#endif
template<typename T> ostream& operator << (ostream& stream, const vector<T>& a) {
  for (auto& x : a) {
    stream << x << ' ';
  }
  return stream;
}
template<typename T1, typename T2> ostream& operator << (ostream& stream, const pair<T1, T2>& p) {
  return stream << p.first << ' ' << p.second;
}

int* find_subset(int L, int R, int* w) {
    int n = sizeof(w);
    debug(n);
    sort(w, w + n);
    if (accumulate(w, w + n, 0LL) < L) {
        return {};
    }
    if (accumulate(w, w + n, 0LL) <= R) {
        int ans[n];
        iota(ans, ans + n, 0);
        return ans;
    }
    if (n <= 1) {
        return {};
    }
    mdebug(w, n);
    int p = n;
    ll suff = 0;
    ll pref = accumulate(w, w + n - 1, 0LL);
    for (int i = n - 2; i >= -1; --i) {
        while (p - 1 > i && suff + w[p - 1] + pref <= R) {
            suff += w[--p];
        }
        debug(i, p, pref, suff);
        if (pref + suff >= L && pref + suff <= R) {
            debug(i + 1 + n - p);
            int ans[i + 1 + n - p];
            debug(sizeof(ans), sizeof(*ans));
            for (int j = 0; j <= i; ++j)
                ans[j] = j;
            for (int j = p; j < n; ++j)
                ans[i + 1 + j - p] = j;
            return ans;
        }
        if (i >= 0) pref -= w[i];
    }
    return {};
}

#ifdef DEBUG
int32_t main() {
#ifdef DEBUG
    freopen("in", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, L, R;
    cin >> n >> L >> R;
    int* w = new int[n];
    for (int i = 0; i < n; ++i) cin >> w[i];
    debug(n);
    mdebug(w, n);
    int[] ans = find_subset(L, R, w);
    int m = sizeof(ans);
    debug(m);
    ll sum = 0;
    for (int i = 0; i < m; ++i)
        sum += w[ans[i]];
    assert(sum == 0 || L <= sum && sum <= R);

    return 0;
}
#endif

Compilation message (stderr)

molecules.cpp: In function 'int* find_subset(int, int, int*)':
molecules.cpp:40:22: warning: statement has no effect [-Wunused-value]
   40 |   #define debug(...) 1337
      |                      ^~~~
molecules.cpp:55:5: note: in expansion of macro 'debug'
   55 |     debug(n);
      |     ^~~~~
molecules.cpp:63:16: warning: address of local variable 'ans' returned [-Wreturn-local-addr]
   63 |         return ans;
      |                ^~~
molecules.cpp:61:13: note: declared here
   61 |         int ans[n];
      |             ^~~
molecules.cpp:41:24: warning: statement has no effect [-Wunused-value]
   41 |   #define mdebug(a, n) 1337
      |                        ^~~~
molecules.cpp:68:5: note: in expansion of macro 'mdebug'
   68 |     mdebug(w, n);
      |     ^~~~~~
molecules.cpp:40:22: warning: statement has no effect [-Wunused-value]
   40 |   #define debug(...) 1337
      |                      ^~~~
molecules.cpp:76:9: note: in expansion of macro 'debug'
   76 |         debug(i, p, pref, suff);
      |         ^~~~~
molecules.cpp:40:22: warning: statement has no effect [-Wunused-value]
   40 |   #define debug(...) 1337
      |                      ^~~~
molecules.cpp:78:13: note: in expansion of macro 'debug'
   78 |             debug(i + 1 + n - p);
      |             ^~~~~
molecules.cpp:40:22: warning: statement has no effect [-Wunused-value]
   40 |   #define debug(...) 1337
      |                      ^~~~
molecules.cpp:80:13: note: in expansion of macro 'debug'
   80 |             debug(sizeof(ans), sizeof(*ans));
      |             ^~~~~
molecules.cpp:85:20: warning: address of local variable 'ans' returned [-Wreturn-local-addr]
   85 |             return ans;
      |                    ^~~
molecules.cpp:79:17: note: declared here
   79 |             int ans[i + 1 + n - p];
      |                 ^~~
/tmp/cc9yLy6T.o: In function `main':
grader.cpp:(.text.startup+0x139): undefined reference to `find_subset(int, int, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status