QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#404495 | #7686. The Phantom Menace | ucup-team3215 | WA | 260ms | 7720kb | C++20 | 4.0kb | 2024-05-04 01:28:51 | 2024-05-04 01:28:53 |
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 01:28:51]
- 提交
answer
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <random>
#include <unordered_map>
#include <vector>
using namespace std;
constexpr uint32_t N = 1e6 + 1, mod = -37u / 2;
vector<int> todo, q;
uint64_t head[N], tail[N];
unordered_map<uint64_t, vector<int>> byh;
uint32_t pw[N], remap[26][2], h[2][N][2];
int nx[N];
unordered_map<uint64_t, vector<uint64_t>> to;
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) {
if (n < 26) {
string t[2]{s[0], s[1]};
sort(t[0].begin(), t[0].end());
sort(t[1].begin(), t[1].end());
if (t[0] != t[1]) return void(cout << "-1\n");
for (int j = 0; j < n; ++j) cout << j + 1 << ' '; cout << '\n';
for (int j = 0; j < n; ++j)
for (int i = 0; i < n; ++i) if (s[1][i] == s[0][j]) cout << i + 1 << ' ', s[1][i] = 0; cout << '\n';
return;
}
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) {
to = {};
byh = {};
for (int i = 0; i < n; ++i) head[i] = hget(0, i * m, d), tail[i] = hget(0, i * m + d, m - d), byh[head[i]].push_back(i), nx[i] = -1;
for (int i = 0; i < n; ++i) to[hget(1, i * m, m - d)].push_back(hget(1, i * m + m - d, d));
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;
byh = {};
for (int i = 0; i < n; ++i) byh[hget(1, i * m, m - d) * 2 ^ hget(1, i * m + m - d, d)].push_back(i);
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]] * 2 ^ head[todo[i + (i != n - 1 ?: 1 - n)]];
q.push_back(byh[h].back()), byh[h].pop_back();
}
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();
}
详细
Test #1:
score: 100
Accepted
time: 6ms
memory: 7548kb
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: 186ms
memory: 7668kb
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: 260ms
memory: 7720kb
input:
500000 1 2 dd ba 1 2 cd ba 1 2 bd ba 1 2 ad ba 1 2 dc ba 1 2 cc ba 1 2 bc ba 1 2 ac ba 1 2 db ba 1 2 cb ba 1 2 bb ba 1 2 ab ba 1 2 da ba 1 2 ca ba 1 2 ba ba 1 2 aa ba 1 2 dd aa 1 2 cd aa 1 2 bd aa 1 2 ad aa 1 2 dc aa 1 2 cc aa 1 2 bc aa 1 2 ac aa 1 2 db aa 1 2 cb aa 1 2 bb aa 1 2 ab aa 1 2 da aa 1 2...
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 500000 cases (500000 test cases)
Test #4:
score: 0
Accepted
time: 111ms
memory: 7520kb
input:
500000 2 1 d d b a 2 1 c d b a 2 1 b d b a 2 1 a d b a 2 1 d c b a 2 1 c c b a 2 1 b c b a 2 1 a c b a 2 1 d b b a 2 1 c b b a 2 1 b b b a 2 1 a b b a 2 1 d a b a 2 1 c a b a 2 1 b a b a 2 1 a a b a 2 1 d d a a 2 1 c d a a 2 1 b d a a 2 1 a d a a 2 1 d c a a 2 1 c c a a 2 1 b c a a 2 1 a c a a 2 1 d...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 2 2 1 -1 -1 1 2 1 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -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 1 2 -1 -1 1 2 2 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 2 1 2 -1 -1 -1 -1 -1 1 2 2 1 -1 -1 -1 -1 -1 -1 -1 -1 -...
result:
ok 500000 cases (500000 test cases)
Test #5:
score: 0
Accepted
time: 219ms
memory: 7488kb
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:
ok 333333 cases (333333 test cases)
Test #6:
score: 0
Accepted
time: 92ms
memory: 7628kb
input:
333333 3 1 c b b b f a 3 1 b b b b f a 3 1 a b b b f a 3 1 f a b b f a 3 1 e a b b f a 3 1 d a b b f a 3 1 c a b b f a 3 1 b a b b f a 3 1 a a b b f a 3 1 f f a b f a 3 1 e f a b f a 3 1 d f a b f a 3 1 c f a b f a 3 1 b f a b f a 3 1 a f a b f a 3 1 f e a b f a 3 1 e e a b f a 3 1 d e a b f a 3 1 c...
output:
-1 -1 -1 1 2 3 2 3 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 2 3 1 2 3 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 2 3 2 1 3 -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 2 3 1 3 2 -1 -1 -1 -1 -...
result:
ok 333333 cases (333333 test cases)
Test #7:
score: 0
Accepted
time: 195ms
memory: 7508kb
input:
250000 1 4 hbca fhaa 1 4 gbca fhaa 1 4 fbca fhaa 1 4 ebca fhaa 1 4 dbca fhaa 1 4 cbca fhaa 1 4 bbca fhaa 1 4 abca fhaa 1 4 haca fhaa 1 4 gaca fhaa 1 4 faca fhaa 1 4 eaca fhaa 1 4 daca fhaa 1 4 caca fhaa 1 4 baca fhaa 1 4 aaca fhaa 1 4 hhba fhaa 1 4 ghba fhaa 1 4 fhba fhaa 1 4 ehba fhaa 1 4 dhba fhaa...
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 250000 cases (250000 test cases)
Test #8:
score: -100
Wrong Answer
time: 77ms
memory: 7440kb
input:
250000 4 1 h b c a f h a a 4 1 g b c a f h a a 4 1 f b c a f h a a 4 1 e b c a f h a a 4 1 d b c a f h a a 4 1 c b c a f h a a 4 1 b b c a f h a a 4 1 a b c a f h a a 4 1 h a c a f h a a 4 1 g a c a f h a a 4 1 f a c a f h a a 4 1 e a c a f h a a 4 1 d a c a f h a a 4 1 c a c a f h a a 4 1 b a c a f...
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 2 3 4 1 2 3 4 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer not cyclic isomorphism (test case 624)