QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#520967#7686. The Phantom MenacepandapythonerWA 487ms3900kbC++234.3kb2024-08-15 18:48:002024-08-15 18:48:01

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-08-15 18:48:01]
  • 评测
  • 测评结果:WA
  • 用时:487ms
  • 内存:3900kb
  • [2024-08-15 18:48:00]
  • 提交

answer

#include <bits/stdc++.h>


using namespace std;


using ll = long long;

#define rep(i, n) for(int i = 0; i < (n); i += 1)
#define rng(i, start, end, step) for(int i = start; i < end; i += step)
#define len(a) ((int)(a).size())


mt19937 rnd(234);

const ll mod = 1e9 + 7;
const ll p = 1235123;


int n, m;
vector<string> a, b;
vector<vector<ll>> pa, pb, sa, sb;

struct edge {
    int to;
    int i;
};


int32_t main() {
    if (1) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
    int tests;
    cin >> tests;
    rep(test, tests) {
        cin >> n >> m;
        a.resize(n);
        b.resize(n);
        rep(i, n) cin >> a[i];
        rep(i, n) cin >> b[i];
        pa.assign(n, vector<ll>(m + 1));
        pb.assign(n, vector<ll>(m + 1));
        sa.assign(n, vector<ll>(m + 1));
        sb.assign(n, vector<ll>(m + 1));
        rep(i, n) {
            pa[i][0] = pb[i][0] = 0;
            rep(j, m) {
                pa[i][j + 1] = (pa[i][j] * p + a[i][j] - 'a' + 1);
                pb[i][j + 1] = (pb[i][j] * p + b[i][j] - 'a' + 1);
            }
            sa[i][0] = sb[i][0] = 0;
            ll pw = 1;
            rep(j, m) {
                sa[i][j + 1] = (sa[i][j] + (a[i][m - j - 1] - 'a' + 1) * pw) % mod;
                sb[i][j + 1] = (sb[i][j] + (b[i][m - j - 1] - 'a' + 1) * pw) % mod;
                pw = pw * p % mod;
            }
        }
        vector<int> p, q;
        for (int len = 1; len <= m; len += 1) {
            vector<ll> left, right;
            rep(i, n) {
                left.push_back(pa[i][len]);
                right.push_back(pb[i][m - len]);
            }
            sort(left.begin(), left.end());
            sort(right.begin(), right.end());
            left.resize(unique(left.begin(), left.end()) - left.begin());
            right.resize(unique(right.begin(), right.end()) - right.begin());
            bool ok = true;
            vector<vector<edge>> g(len(left) + len(right));
            rep(i, n) {
                if (!binary_search(right.begin(), right.end(), sa[i][m - len])) {
                    ok = false;
                    break;
                }
                if (!binary_search(left.begin(), left.end(), sb[i][len])) {
                    ok = false;
                    break;
                }
            }
            if (!ok) {
                continue;
            }
            vector<int> d(len(left) + len(right));
            rep(i, n) {
                int u = lower_bound(left.begin(), left.end(), pa[i][len]) - left.begin();
                int v = lower_bound(right.begin(), right.end(), sa[i][m - len]) - right.begin();
                v += len(left);
                g[u].push_back(edge{ v, i });
                d[u] += 1; d[v] -= 1;

                u = lower_bound(right.begin(), right.end(), pb[i][m - len]) - right.begin();
                v = lower_bound(left.begin(), left.end(), sb[i][len]) - left.begin();
                u += len(left);
                g[u].push_back(edge{ v, n + i });
                d[u] += 1; d[v] -= 1;
            }
            if (!all_of(d.begin(), d.end(), [&](int x) {return x == 0;})) continue;
            vector<int> pntr(2 * n, 0);
            int start = 0;
            while (start < 2 * n and g[start].empty()) ++start;
            assert(start < 2 * n);
            function<void(int)> dfs;
            vector<int> way;
            dfs = [&](int v) {
                for (int& i = pntr[v]; i < len(g[v]);) {
                    auto [to, e] = g[v][i];
                    i += 1;
                    dfs(to);
                    way.push_back(e);
                }
                };
            dfs(start);
            if (len(way) != 2 * n) continue;
            reverse(way.begin(), way.end());
            for (auto x : way) {
                if (x < n) {
                    p.push_back(x);
                } else {
                    q.push_back(x - n);
                }
            }
            assert(len(p) == n and len(q) == n);
            break;
        }
        if (p.empty() or q.empty()) {
            cout << -1 << "\n";
        } else {
            for (auto x : p) cout << x + 1 << " "; cout << "\n";
            for (auto x : q) cout << x + 1 << " "; cout << "\n";
        }
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3660kb

input:

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

output:

1 3 2 
1 2 3 
-1

result:

ok 2 cases (2 test cases)

Test #2:

score: 0
Accepted
time: 487ms
memory: 3604kb

input:

1000000
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
b
b
1 1
a
b
1 1
b
a
1 1
a
a
1 1
...

output:

1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
1 
1 
1 
1 
-1
-1
...

result:

ok 1000000 cases (1000000 test cases)

Test #3:

score: 0
Accepted
time: 217ms
memory: 3660kb

input:

500000
1 2
dd
ba
1 2
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-1
-1
-1
-1
-1
-1
-1
1 2 
1 2 
1 2 
1 2 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 2 
2 1 
-1
-1
2 1 
2 1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 2 
2 1 
-1
-1
-1
-1
-1
2 1 
2 1 
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

ok 500000 cases (500000 test cases)

Test #5:

score: -100
Wrong Answer
time: 152ms
memory: 3668kb

input:

333333
1 3
cbb
bfa
1 3
bbb
bfa
1 3
abb
bfa
1 3
fab
bfa
1 3
eab
bfa
1 3
dab
bfa
1 3
cab
bfa
1 3
bab
bfa
1 3
aab
bfa
1 3
ffa
bfa
1 3
efa
bfa
1 3
dfa
bfa
1 3
cfa
bfa
1 3
bfa
bfa
1 3
afa
bfa
1 3
fea
bfa
1 3
eea
bfa
1 3
dea
bfa
1 3
cea
bfa
1 3
bea
bfa
1 3
aea
bfa
1 3
fda
bfa
1 3
eda
bfa
1 3
dda
bfa
1 3
c...

output:

-1
-1
-1
1 
1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1 
1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

wrong answer Jury has the answer but participant has not (test case 14)