QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#354745#7858. Basic Equation Solvingucup-team3215Compile Error//C++203.8kb2024-03-15 22:31:152024-03-15 22:31:16

Judging History

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

  • [2024-03-20 11:12:17]
  • hack成功,自动添加数据
  • (/hack/581)
  • [2024-03-15 22:31:16]
  • 评测
  • [2024-03-15 22:31:15]
  • 提交

answer

#include <algorithm>
#include <array>
#include <iostream>
#include <vector>

using namespace std;

constexpr int mod = 998244353;

auto& add(auto&& a, auto b) { return a -= (a += b) >= mod? mod: 0; }
auto& mul(auto&& a, auto b) { return a = a * (uint64_t)b % mod; }

struct DSU {
  int p[36];

  DSU() { fill(p, p + 36, -1); }

  int operator()(int v) { return getp(v); }
  bool operator()(int u, int v) { return uni(u, v); }
  bool operator[](array<int, 2> uv) { return getp(uv[0]) == getp(uv[1]); }
  int getp(int v) { return p[v] < 0? v: p[v] = getp(p[v]); }
  bool uni(int u, int v) { return (u = getp(u)) != (v = getp(v))? p[v] = u, 1: 0; }
};

int dp[1 << 11];

int solve(auto& gr, vector<int> val) {
  int n = val.size();
  fill_n(dp, 1 << n, 0);
  vector<int> mgr(n);
  for (auto [a, b]: gr) mgr[b] |= 1 << a;
  dp[0] = 1;
  for (int v = 10; v--; )
  for (int m = 1 << n; m--; ) if (dp[m]) {
    int ava = 0;
    for (int i = 0; i < n; ++i) if (!(m >> i & 1) && !(mgr[i] & ~m) && (!~val[i] || val[i] == v)) ava |= 1 << i;
    for (int t = 0; --t &= ava; ) add(dp[m + t], dp[m]);
  }
  return dp[(1 << n) - 1];
}

vector<vector<array<int, 2>>> compe(36);
vector<vector<int>> compv(36);
vector<vector<int>> compval(36);

int solve(auto& gr, DSU eq) {
  DSU weak;
  for (auto& x: compe) x = {};
  for (auto& x: compv) x = {};
  for (auto& x: compval) x = {};
  for (auto [a, b]: gr) if (min(a, b) > 9) weak(a, b);
  for (auto [a, b]: gr) if (max(a, b) > 9 && min(a, b) <= 9) compv[weak(max(a, b))].push_back(min(a, b));
  for (int i = 10; i < 36; ++i) sort(compv[i].begin(), compv[i].end()), compv[i].erase(unique(compv[i].begin(), compv[i].end()), compv[i].end());
  for (int i = 10; i < 36; ++i) if (eq(i) == i) compv[weak(i)].push_back(i);
  for (int i = 10; i < 36; ++i) if (weak(i) == i) compval[i].assign(compv[i].size(), -1);
  for (int i = 10; i < 36; ++i) for (int j = 0; j < compv[i].size(); ++j) if (compv[i][j] <= 9) compval[i][j] = compv[i][j];
  auto id = [&](int c, int v) {
    auto& loc = compv[c];
    return find(loc.begin(), loc.end(), v) - loc.begin();
  };
  for (auto [a, b]: gr) if (max(a, b) > 9) { int c = weak(max(a, b)); compe[c].push_back({id(c, a), id(c, b)}); }
  int ans = 1;
  for (int i = 10; i < 36; ++i) if (compv[i].size()) {
    mul(ans, solve(compe[i], compval[i]));
  }
  return ans;
}

vector<array<string, 2>> inp;
int ans;

bool isgr(auto& gr, int a, int b) {
  uint64_t vis = 1ull << a;
  for (int ch = 1; ch--; )
  for (auto [x, y]: gr) if ((vis >> x & 1) && !(vis >> y & 1)) ch = 1, vis |= 1ull << y;
  return vis >> b & 1;
}

void solve(auto gr, DSU eq, int i) {
  if (i == inp.size()) return void(add(ans, solve(gr, eq)));
  for (int j = 0; j < inp[i][0].size(); ++j) if (int a = eq(inp[i][0][j]), b = eq(inp[i][1][j]); a != b) {
    if (isgr(gr, b, a)) return;
    if (isgr(gr, a, b)) return solve(gr, eq, i + 1);
    gr.push_back({a, b}), solve(gr, eq, i + 1), gr.pop_back();
    eq(min(a, b), max(a, b));
    for (auto& [a, b]: gr) a = eq(a), b = eq(b);
  }
}

int main() {
  DSU eq;
  vector<array<int, 2>> gr;
  for (int i = 0; i < 9; ++i) gr.push_back({i + 1, i});
  int n; cin >> n;
  for (int i = 0; i < n; ++i) {
    string s, t, o; cin >> s;
    for (auto c: "=><"s) if (auto i = s.find(c); ~i) o = ""s + c, t = s.substr(0, i), s = s.substr(i + 1);
    if (s.size() < t.size()) s.insert(s.begin(), t.size() - s.size(), '0');
    if (s.size() > t.size()) t.insert(t.begin(), s.size() - t.size(), '0');
    for (auto& c: s) c = c <= '9'? c - '0': c - 'A' + 10;
    for (auto& c: t) c = c <= '9'? c - '0': c - 'A' + 10;
    if (o == ">") swap(s, t);
    if (o == "=") for (int i = 0; i < s.size(); ++i) eq(min(s[i], t[i]), max(s[i], t[i]));
    else inp.push_back({s, t});
  }
  solve(gr, eq, 0);
  cout << ans << '\n';
}


Details

answer.code: In function ‘auto& mul(auto:21&&, auto:22)’:
answer.code:11:47: error: ‘uint64_t’ was not declared in this scope
   11 | auto& mul(auto&& a, auto b) { return a = a * (uint64_t)b % mod; }
      |                                               ^~~~~~~~
answer.code:5:1: note: ‘uint64_t’ is defined in header ‘<cstdint>’; did you forget to ‘#include <cstdint>’?
    4 | #include <vector>
  +++ |+#include <cstdint>
    5 | 
answer.code:11:56: error: expected ‘;’ before ‘b’
   11 | auto& mul(auto&& a, auto b) { return a = a * (uint64_t)b % mod; }
      |                                                        ^
      |                                                        ;
answer.code: In function ‘bool isgr(auto:25&, int, int)’:
answer.code:73:3: error: ‘uint64_t’ was not declared in this scope
   73 |   uint64_t vis = 1ull << a;
      |   ^~~~~~~~
answer.code:73:3: note: ‘uint64_t’ is defined in header ‘<cstdint>’; did you forget to ‘#include <cstdint>’?
answer.code:75:30: error: ‘vis’ was not declared in this scope
   75 |   for (auto [x, y]: gr) if ((vis >> x & 1) && !(vis >> y & 1)) ch = 1, vis |= 1ull << y;
      |                              ^~~
answer.code:76:10: error: ‘vis’ was not declared in this scope
   76 |   return vis >> b & 1;
      |          ^~~
answer.code: In instantiation of ‘int solve(auto:24&, DSU) [with auto:24 = std::vector<std::array<int, 2> >]’:
answer.code:80:50:   required from ‘void solve(auto:26, DSU, int) [with auto:26 = std::vector<std::array<int, 2> >]’
answer.code:106:8:   required from here
answer.code:61:93: warning: narrowing conversion of ‘id.solve<std::vector<std::array<int, 2> > >(std::vector<std::array<int, 2> >&, DSU)::<lambda(int, int)>(c, a)’ from ‘long int’ to ‘int’ [-Wnarrowing]
   61 |   for (auto [a, b]: gr) if (max(a, b) > 9) { int c = weak(max(a, b)); compe[c].push_back({id(c, a), id(c, b)}); }
      |                                                                                           ~~^~~~~~
answer.code:61:103: warning: narrowing conversion of ‘id.solve<std::vector<std::array<int, 2> > >(std::vector<std::array<int, 2> >&, DSU)::<lambda(int, int)>(c, b)’ from ‘long int’ to ‘int’ [-Wnarrowing]
   61 |   for (auto [a, b]: gr) if (max(a, b) > 9) { int c = weak(max(a, b)); compe[c].push_back({id(c, a), id(c, b)}); }
      |                                                                                                     ~~^~~~~~