Submission #897954

#TimeUsernameProblemLanguageResultExecution timeMemory
897954duckindogDetecting Molecules (IOI16_molecules)C++14
Compilation error
0 ms0 KiB
// from duckindog wth depression
#include<bits/stdc++.h>

using namespace std;

#define LOCAL

#ifndef LOCAL
#include "molecules.h"
#endif // LOCAL

struct T {
  int a, b;

  T(int aa, int bb) : a(aa), b(bb) {}
};
const int N = 1e4 + 1;
bool f[2][N];
pair<int, int> trace[N][N];
vector<int> find_subset(int l, int u, vector<int> w) {
  int n = w.size();

  for (int i = 1; i < n; ++i) {
    int it = i - 1 & 1;
    for (int j = 1; j <= u; ++j) f[1 - it][j] = 0;
    f[1 - it][0] = f[1 - it][w[i - 1]] = 1;

    for (int j = 1; j <= u; ++j) {
      auto &ret = f[it][j];
      if (f[1 - it][j]) {
        ret = 1;
        trace[i][j] = {i - 1, j};
      }
      if (j - w[i] >= 0 && f[1 - it][j - w[i]]) {
        ret = 1;
        trace[i][j] = {i - 1, j - w[i]};
      }
    }
  }

  vector<int> answer;
  int i = n - 1, j = 0;
  for (int x = l; x <= u; ++x) if (f[i & 1][x]) j = x;

  while (j) {
    int pi, pj; tie(pi, pj) = trace[i][j];
    if (j > pj) answer.push_back(i);
    i = pi; j = pj;
  }
  return answer;
}

#ifdef LOCAL
int32_t main() {
  cin.tie(0)->sync_with_stdio(0);

  if (fopen("duck.inp", "r")) {
    freopen("duck.inp", "r", stdin);
    freopen("duck.out", "w", stdout);
  }

  int l, u; cin >> l >> u;
  int x;
  vector<int> input;
  while (cin >> x) input.push_back(x);

  for (auto i : find_subset(l, u, input))
    cout << i << ' ';
}
#endif // LOCAL

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:24:16: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   24 |     int it = i - 1 & 1;
      |              ~~^~~
molecules.cpp: In function 'int32_t main()':
molecules.cpp:58:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |     freopen("duck.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
molecules.cpp:59:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |     freopen("duck.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccn0Lf45.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccWDxyy7.o:molecules.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status