QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#401514#8005. Crossing the BorderMade_in_CodeCompile Error//C++142.1kb2024-04-28 21:13:382024-04-28 21:13:38

Judging History

你现在查看的是最新测评结果

  • [2024-04-28 21:13:38]
  • 评测
  • [2024-04-28 21:13:38]
  • 提交

answer

#include <algorithm>
#include <fstream>
#include <vector>
#define LL long long
#define PII pair<LL, LL>

using namespace std;

const LL kMaxN = 22, kInf = 2e9, kMod = 998244353;
LL n, m, k, w[1 << kMaxN], d[1 << kMaxN];
PII a[kMaxN], f[1 << kMaxN];
vector<LL> p[1 << kMaxN];

PII Add(PII x, LL y) { return {x.first + y, x.second}; }

void Merge(PII &x, PII y) {
  if (x.first > y.first) {
    x = y;
  } else if (x.first == y.first) {
    x.second = (x.second + y.second) % kMod;
  }
}

bool C(LL s, LL t) { return (s & -s) ^ (t & -t); }

int main() {
  cin.tie(0), cout.tie(0);
  ios::sync_with_stdio(0);
  cin >> n >> k;
  for (LL i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  m = n >> 1, sort(a, a + n, [](PII i, PII j) {
    return i.second > j.second;
  });
  for (LL i = 0; i < n; i++) {
    w[1 << i] = a[i].first, d[1 << i] = a[i].second;
  }
  for (LL s = 0; s < 1 << n; s++) {
    f[s] = {s ? kInf : 0, 1};
    if (s & s - 1 ^ s) {
      w[s] = w[s & s - 1] + w[s & -s];
      d[s] = d[s & -s];
    }
  }
  for (LL s = 0; s < 1 << m; s++) {
    for (LL t = s; t; t = t - 1 & s) {
      if (C(t - 1 & s, s)) {
        p[s].push_back(t - 1 & s);
      }
    }
    sort(p[s].begin(), p[s].end(), [](LL i, LL j) {
      return w[i] > w[j];
    });
  }
  for (LL s = 0; s < 1 << n - m; s++) {
    for (LL t = s; t < 1 << n - m; t = t + 1 | s) {
      p[s << m].push_back(t << m);
    }
    sort(p[s << m].begin(), p[s << m].end(), [](LL i, LL j) {
      return w[i] > w[j];
    });
  }
  for (LL s = 0; s < 1 << n; s++) {
    LL l = s & ~(-1 << m), r = s >> m << m;
    PII g = {kInf, 1};
    for (LL i = 0, j = 0; j < p[r].size(); j++) {
      LL _r = p[r][j];
      for (; l && i < p[l].size(); i++) {
        LL _l = p[l][i];
        if (w[_l] + w[r] + k >= w[l] + w[_r]) {
          Merge(g, Add(f[_l | r], d[l]));
        } else {
          break;
        }
      }
      Merge(f[l | _r], g);
      if (C(_r, r) && w[r] + k >= w[_r]) {
        Merge(f[l | _r], Add(f[l | r], d[_r]));
      }
    }
  }
  cout << f[~(-1 << n)].first << ' ' << f[~(-1 << n)].second << '\n';
  return 0;
}

詳細信息

answer.code: In function ‘int main()’:
answer.code:27:3: error: ‘cin’ was not declared in this scope
   27 |   cin.tie(0), cout.tie(0);
      |   ^~~
answer.code:4:1: note: ‘std::cin’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?
    3 | #include <vector>
  +++ |+#include <iostream>
    4 | #define LL long long
answer.code:27:15: error: ‘cout’ was not declared in this scope
   27 |   cin.tie(0), cout.tie(0);
      |               ^~~~
answer.code:27:15: note: ‘std::cout’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’?