QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#409029#7686. The Phantom Menacelight_ink_dots#WA 8ms63612kbC++143.3kb2024-05-11 16:03:572024-05-11 16:03:58

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-11 16:03:58]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:63612kb
  • [2024-05-11 16:03:57]
  • 提交

answer

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

int main() {
    typedef __int128 i128;
    static const i128 base = 233, mod = 1000000000000000009;
    static const int maxn = 1000010;
    int t;
    scanf("%d", &t);
    while (t--) {
        int n, m;
        scanf("%d %d", &n, &m);
        static char A[maxn], B[maxn];
        for (int i = 0; i < n; i++) scanf("%s", A + i * m);
        for (int i = 0; i < n; i++) scanf("%s", B + i * m);
        static i128 pw[maxn], Ha[maxn], Hb[maxn];
        for (int i = 0; i <= n * m; i++) pw[i] = !i ? 1 : pw[i - 1] * base % mod;
        for (int i = 0; i < n * m; i++) Ha[i] = ((!i ? 0 : Ha[i - 1] * base) + A[i]) % mod;
        for (int i = 0; i < n * m; i++) Hb[i] = ((!i ? 0 : Hb[i - 1] * base) + B[i]) % mod;
        auto get = [](const i128* h, const int l, const int r) {
            return (h[r] - (!l ? 0 : h[l - 1] * pw[r - l + 1] % mod) + mod) % mod;
        };
        bool ans = false;
        static int p[maxn], q[maxn];
        for (int d = 0; d < m; d++) {
            int tot = 0;
            unordered_map<long long, int> pre, suf;
            for (int i = 0; i < n; i++) {
                long long p = get(Ha, i * m, i * m + d - 1);
                long long s = get(Ha, i * m + d, (i + 1) * m - 1);
                if (!pre.count(p))
                    pre[p] = ++tot;
                if (!suf.count(s))
                    suf[s] = ++tot;
            }
            struct edge {
                int to, id;
            };
            static vector<edge> G[maxn << 1];
            static int in[maxn << 1], out[maxn << 1];
            for (int i = 1; i <= tot; i++) G[i].clear(), in[i] = out[i] = 0;
            for (int i = 0; i < n; i++) {
                int p = pre[get(Ha, i * m, i * m + d - 1)];
                int s = suf[get(Ha, i * m + d, (i + 1) * m - 1)];
                G[p].push_back({ s, i }), out[p]++, in[s]++;
            }
            bool flag = true;
            for (int i = 0; i < n; i++) {
                int p = suf[get(Hb, i * m, i * m + (m - d) - 1)];
                int s = pre[get(Hb, (i + 1) * m - d, (i + 1) * m - 1)];
                if (!p || !s) {
                    flag = false;
                    break;
                }
                G[p].push_back({ s, i + n }), out[p]++, in[s]++;
            }
            for (int i = 1; i <= tot; i++) flag &= in[i] == out[i];
            if (!flag)
                continue;
            static vector<int> ord;
            function<void(int)> dfs = [&dfs](const int u) {
                while (!G[u].empty()) {
                    auto e = G[u].back();
                    G[u].pop_back();
                    dfs(e.to), ord.push_back(e.id);
                }
                return;
            };
            ord.clear();
            for (int s = 1; s <= tot; s++) dfs(s);
            int cA = 0, cB = 0;
            for (int i : ord) i < n ? p[++cA] = i : q[++cB] = i - n;
            ans = true;
            break;
        }
        if (ans) {
            for (int i = 1; i <= n; i++) printf("%d ", p[i] + 1);
            printf("\n");
            for (int i = 1; i <= n; i++) printf("%d ", q[i] + 1);
            printf("\n");
        } else
            printf("-1\n");
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 63612kb

input:

2
3 3
abc
ghi
def
bcd
efg
hia
1 3
abc
def

output:

2 3 1 
3 2 1 
-1

result:

wrong answer not cyclic isomorphism (test case 1)