QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#404513#7686. The Phantom Menaceucup-team3215Compile Error//C++204.4kb2024-05-04 02:07:272024-05-04 02:07:27

Judging History

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

  • [2024-10-08 14:11:03]
  • hack成功,自动添加数据
  • (/hack/941)
  • [2024-10-08 10:05:28]
  • hack成功,自动添加数据
  • (/hack/940)
  • [2024-10-07 19:51:15]
  • hack成功,自动添加数据
  • (/hack/938)
  • [2024-10-07 19:28:01]
  • hack成功,自动添加数据
  • (/hack/937)
  • [2024-10-07 17:16:32]
  • hack成功,自动添加数据
  • (/hack/936)
  • [2024-10-07 16:53:09]
  • hack成功,自动添加数据
  • (/hack/935)
  • [2024-10-07 16:22:17]
  • hack成功,自动添加数据
  • (/hack/934)
  • [2024-05-04 02:07:27]
  • 评测
  • [2024-05-04 02:07:27]
  • 提交

answer

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <random>
#include <vector>

using namespace std;

constexpr uint32_t N = 1e6 + 1, mod = -37u / 2;

vector<int> todo, q;
array<uint64_t, 2> tmp[2][N];
int head[N], tail[N], headb[N], tailb[N];
vector<int> byh[N];

uint32_t pw[N], remap[26][2], h[2][N][2];

int nx[N];
vector<int> to[N];

uint64_t hget(int x, int l, int n) { return (h[x][l][0] * (uint64_t)pw[n] + mod - h[x][l + n][0]) % mod << 31 |
                                            (h[x][l][1] * (uint64_t)pw[n] + mod - h[x][l + n][1]) % mod; }

bool extend(int v) {
  int skipped = 0;
  for (auto it = to[tail[v]].end(); it != to[tail[v]].begin(); ) {
    auto x = *--it;
    while (byh[x].size()) {
      auto y = byh[x].back(); byh[x].pop_back();
      to[tail[v]].erase(it);
      todo.push_back(y);
      return extend(nx[v] = y);
    }
    if (skipped++) return 0;
  }
  return 1;
}

void solve() {
  int n, m; cin >> n >> m;
  string s[2];
  for (int i = 0; i < 2 * n; ++i) { string c; cin >> c, s[i >= n] += c; }
  if (m == 1) {
    int cnts[2][26]{};
    for (int i: {0, 1})
    for (int j = 0; j < n; ++j) ++cnts[i][s[i][j] - 'a'];
    for (int j = 0; j < 26; ++j) if (cnts[0][j] != cnts[1][j]) return void(cout << "-1\n");
    vector<int> r[2];
    for (int i: {0, 1}) {
      r[i].resize(n);
      partial_sum(cnts[i], end(cnts[i]), cnts[i]), rotate(cnts[i], end(cnts[i]) - 1, end(cnts[i])), cnts[i][0] = 0;
      for (int j = 0; j < n; ++j) r[i][cnts[i][s[i][j] - 'a']++] = j;
    }
    for (auto x: r[0]) cout << x + 1 << ' '; cout << '\n';
    for (auto x: r[1]) cout << x + 1 << ' '; cout << '\n';
    return;
  }
  for (int x: {0, 1}) for (int y: {0, 1})
  for (int i = 0, p = 0; i < n * m; ++i) h[x][i + 1][y] = p = (p * 3ull + remap[s[x][i] - 'a'][y]) % mod;
  for (int d = 0; d < m; ++d) {
    for (int i = 0; i < n; ++i) to[i].clear(), byh[i].clear();
    for (int i = 0; i < n; ++i) {
      tmp[0][i] = {hget(0, i * m, d), i};
      tmp[1][i] = {hget(1, i * m + m - d, d), i};
      nx[i] = -1;
    }
    bool fail = 0;
    sort(tmp[0], tmp[0] + n);
    sort(tmp[1], tmp[1] + n);
    for (int i = 0, j = 0; i < n; ++i) {
      j += i && tmp[0][i][0] != tmp[0][i - 1][0];
      if (tmp[0][i][0] != tmp[1][i][0]) fail = 1;
      byh[j].push_back(tmp[0][i][1]);
      head[tmp[0][i][1]] = j;
      tailb[tmp[1][i][1]] = j;
    }
    for (int i = 0; i < n; ++i) {
      tmp[0][i] = {hget(0, i * m + d, m - d), i};
      tmp[1][i] = {hget(1, i * m, m - d), i};
    }
    sort(tmp[0], tmp[0] + n);
    sort(tmp[1], tmp[1] + n);
    for (int i = 0, j = 0; i < n; ++i) {
      j += i && tmp[0][i][0] != tmp[0][i - 1][0];
      if (tmp[0][i][0] != tmp[1][i][0]) fail = 1;
      to[j].push_back(tailb[tmp[1][i][1]]);
      headb[tmp[1][i][1]] = j;
      tail[tmp[0][i][1]] = j;
    }
    if (fail) continue;
    byh[head[0]].erase(find(byh[head[0]].begin(), byh[head[0]].end(), 0));
    todo = {{}};
    if (!extend(0)) todo = {};
    else if (int x = todo.back(); to[tail[x]].empty() || to[tail[x]][0] != head[0]) todo = {};
    else to[tail[x]] = {}, nx[x] = 0;
    for (int i = 0; i < todo.size(); ++i) {
      int x = todo[i], y = nx[x];
      to[tail[x]].push_back(head[y]);
      if (!extend(x)) { todo = {}; break; }
      if (nx[x] == y) {
        to[tail[x]].pop_back();
        continue;
      }
      --i;
      x = todo.back();
      if (to[tail[x]].empty() || to[tail[x]][0] != head[y]) { todo = {}; break; }
      to[tail[x]] = {}, nx[x] = y;
    }
    if (todo.size() != n) continue;
    for (int i = 0; i < n; ++i) tmp[0][i] = {headb[i] + 0ull << 32 | tailb[i], i + 1};
    sort(tmp[0], tmp[0] + n);
    todo = q = {};
    for (int i = 0; todo.push_back(i), i = nx[i]; ) ;
    for (int i = 0; i < n; ++i) {
      auto h = tail[todo[i]] + 0ull << 32 | head[todo[i + (i != n - 1 ?: 1 - n)]];
      auto it = upper_bound(tmp[0], tmp[0] + n, array<uint64_t, 2>{h, 0});
      q.push_back(it->back() - 1);
      it->back() = 0;
    }
    for (auto x: todo) cout << x + 1 << ' '; cout << '\n';
    for (auto x: q) cout << x + 1 << ' '; cout << '\n';
    return;
  }
  cout << "-1\n";
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  generate(*remap, *end(remap), mt19937_64{163467});
  for (int i = 0, p = 1; i < N; ++i) pw[i] = p, p = p * 3ull % mod;
  for (int tc = (cin >> tc, tc); tc--; ) solve();
}

詳細信息

answer.code:12:20: error: elements of array ‘std::array<long unsigned int, 2> tmp [2][1000001]’ have incomplete type
   12 | array<uint64_t, 2> tmp[2][N];
      |                    ^~~
answer.code:12:20: error: storage size of ‘tmp’ isn’t known
answer.code: In function ‘void solve()’:
answer.code:116:72: error: too many initializers for ‘std::array<long unsigned int, 2>’
  116 |       auto it = upper_bound(tmp[0], tmp[0] + n, array<uint64_t, 2>{h, 0});
      |                                                                        ^