QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#295033#7940. Impossible Numbersckiseki#WA 1ms3956kbC++204.3kb2023-12-30 18:04:152023-12-30 18:04:16

Judging History

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

  • [2023-12-30 18:04:16]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3956kb
  • [2023-12-30 18:04:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
  cerr << "\e[1;32m(" << s << ") = (";
  int f = 0;
  (..., (cerr << (f++ ? ", " : "") << a));
  cerr << ")\e[0m\n";
}
#include <experimental/iterator>
void orange_(auto s, auto L, auto R) {
  cerr << "\e[1;33m[ " << s << " ] = [ ";
  using namespace experimental;
  copy(L, R, make_ostream_joiner(cerr, ", "));
  cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define orange(...) safe
#define debug(...) safe
#endif

template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

struct Int {
  string s;
  bool operator<(const Int &rhs) const {
    if (s.size() != rhs.s.size())
      return s.size() < rhs.s.size();
    for (int i = 0; i < ssize(s); ++i)
      if (s[i] != rhs.s[i])
        return s[i] < rhs.s[i];
    return false;
  }
  bool operator>(const Int &rhs) const {
    if (s.size() != rhs.s.size())
      return s.size() > rhs.s.size();
    for (int i = 0; i < ssize(s); ++i)
      if (s[i] != rhs.s[i])
        return s[i] > rhs.s[i];
    return false;
  }
};

ostream &operator<<(ostream &os, const Int &s) {
  return os << s.s;
}

struct H {
  int l;
  vector<int> ds, p;
  H(vector<int> ds_, int c) : l(c), ds(ds_), p(ds.size()) {
    for (size_t i = 1; i < p.size(); ++i) {
      p[i] = l - (p.size() - i);
    }
  }
  bool operator>(const H &rhs) const {
    return gen() > rhs.gen();
  }
  Int gen() const {
    Int ret;
    ret.s.assign(l, '0');
    for (size_t i = 0; i + 1 < p.size(); ++i) {
      for (int j = p[i]; j < p[i + 1]; ++j)
        ret.s[j] = char(ds[i] + '0');
    }
    for (int i = p.back(); i < l; ++i)
      ret.s[i] = char(ds.back() + '0');
    if (ret.s[0] == '0') {
      for (int j = 1; j < l; ++j) {
        if (ret.s[j] != '0') {
          swap(ret.s[0], ret.s[j]);
          break;
        }
      }
    }
    return ret;
  }
  bool step() {
    for (size_t i = 1; i <= p.size(); ++i) {
      p[p.size() - i]--;
      if (i == p.size())
        return false;
      if (p[p.size() - i] == p[p.size() - i - 1]) {
        p[p.size() - i] = l - i;
      } else {
        break;
      }
    }
    return true;
  }
};

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<uint32_t> a(n);
  for (auto &S : a) {
    for (int i = 0; i < 6; ++i) {
      int x;
      cin >> x;
      S |= 1u << x;
    }
  }

  min_heap<H> h;

  set<array<int, 10>> done;
  min_heap<Int> ans;
  for (uint32_t S = 2; S < 1024; ++S) {
    int c = 0;
    for (auto s : a)
      c += !!(S & s);
    ++c;

    vector<int> ds;
    for (int i = 0; i < 10; ++i) {
      if ((S >> i) & 1)
        ds.push_back(i);
    }

    c = max(c, int(ds.size()));
    
    h.emplace(ds, c);
   }

  for (int i = 0; i < k; ++i) {
    while (not h.empty()) {
      if (ans.empty() or h.top().gen() < ans.top()) {
        auto cur = h.top();
        h.pop();
        auto curi = cur.gen();
        array<int, 10> ds = {};
        for (auto c : curi.s)
          ds[c - '0']++;
        if (done.insert(ds).second)
          ans.push(curi);
        if (cur.step()) {
          h.push(cur);
        }
      } else {
        break;
      }
    }
    auto cur = ans.top();
    ans.pop();
    cout << cur << " \n"[i + 1 == k];
    if (next_permutation(all(cur.s))) {
      ans.push(cur);
    } else {
      array<int, 10> ds = {};
      for (auto c : cur.s)
        ds[c - '0']++;

      for (int c = 0; c < 10; ++c) {
        ds[c]++;
        if (done.insert(ds).second) {
          Int nxt;
          int found = -1;
          if (ds[0] > 0) {
            for (int x = 1; x < 10; ++x) {
              if (ds[x]) {
                found = x;
                break;
              }
            }
          }
          if (ds[0] == 0 or found != -1) {
            if (found != -1) {
              nxt.s += char('0' + found);
              ds[found]--;
            }
            for (int x = 0; x < 10; ++x)
              for (int w = 0; w < ds[x]; ++w)
                nxt.s += char('0' + x);
            ans.push(nxt);
            if (found != -1) {
              ds[found]++;
            }
          }
        }
        ds[c]--;
      }
    }
  }
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3880kb

input:

2 3
1 8 7 0 6 2
1 2 5 4 9 3

output:

33 34 35

result:

ok single line: '33 34 35'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3736kb

input:

1 10
1 5 2 2 6 4

output:

3 7 8 9 10 11 12 13 14 15

result:

ok single line: '3 7 8 9 10 11 12 13 14 15'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3956kb

input:

4 10
1 5 7 1 2 4
0 1 5 8 9 4
3 5 2 2 7 8
6 1 7 0 2 2

output:

33 66 99 133 166 199 233 266 299 303

result:

ok single line: '33 66 99 133 166 199 233 266 299 303'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3724kb

input:

5 10
5 9 4 8 3 3
1 1 9 2 8 9
6 3 3 0 2 1
2 6 0 3 6 4
3 6 4 2 9 4

output:

7 17 27 37 47 55 57 67 70 71

result:

ok single line: '7 17 27 37 47 55 57 67 70 71'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3728kb

input:

5 10
8 7 1 4 8 9
2 5 0 1 0 1
9 5 5 3 9 7
6 0 0 2 3 1
1 0 0 4 9 3

output:

66 88 166 188 222 226 262 266 288 366

result:

ok single line: '66 88 166 188 222 226 262 266 288 366'

Test #6:

score: 0
Accepted
time: 1ms
memory: 3644kb

input:

5 10
6 8 7 7 0 0
0 5 1 9 4 1
5 9 6 9 5 4
0 4 6 9 1 6
2 8 7 4 4 0

output:

3 13 22 23 30 31 32 33 34 35

result:

ok single line: '3 13 22 23 30 31 32 33 34 35'

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 3772kb

input:

5 1000
0 4 1 3 9 6
9 6 2 1 8 6
5 3 0 7 7 3
0 2 8 0 8 4
2 4 1 2 9 7

output:

55 155 255 333 335 353 355 455 505 515 525 533 535 545 550 551 552 553 554 555 556 557 558 559 565 575 577 585 595 655 666 755 757 775 777 855 888 955 1055 1111 1116 1119 1155 1161 1166 1169 1191 1196 1199 1255 1333 1335 1353 1355 1455 1505 1515 1525 1533 1535 1545 1550 1551 1552 1553 1554 1555 1556...

result:

wrong answer 1st lines differ - expected: '55 155 255 333 335 353 355 455...0 10053 10055 10111 10116 10119', found: '55 155 255 333 335 353 355 455...3 10055 10111 10116 10119 10155'