QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#251003 | #7686. The Phantom Menace | Hayasa | WA | 283ms | 262920kb | C++20 | 3.8kb | 2023-11-13 23:56:43 | 2023-11-13 23:56:44 |
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)
- [2023-11-13 23:56:43]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> pii;
typedef long long ll;
typedef vector <int> vi;
const int MAX_N = 1000000 + 5;
const int Base1 = 233;
const int Base2 = 567;
const int Mod1 = 1258489069;
const int Mod2 = 1453570957;
void init();
int N, M, pw1[MAX_N], pw2[MAX_N];
char str[MAX_N];
string s[MAX_N], t[MAX_N];
int ids[MAX_N], idt[MAX_N];
struct Hash{
vector <int> ha1, ha2;
void build(const char *s) {
ha1.resize(M + 1);
ha2.resize(M + 1);
ha1[0] = ha2[0] = 0;
for (int i = 1; i <= M; i ++) {
ha1[i] = (1ll * ha1[i - 1] * Base1 + s[i]) % Mod1;
ha2[i] = (1ll * ha2[i - 1] * Base2 + s[i]) % Mod2;
}
}
pii get(int l, int r) {
int res1 = (ha1[r] - 1ll * ha1[l - 1] * pw1[r - l + 1] + 1ll * Mod1 * Mod1) % Mod1;
int res2 = (ha2[r] - 1ll * ha2[l - 1] * pw2[r - l + 1] + 1ll * Mod2 * Mod2) % Mod2;
return {res1, res2};
}
}has[MAX_N], hat[MAX_N];
vector <pii> edge[MAX_N << 2];
int ecur[MAX_N<<2];
vi ans;
inline bool cmp_s(int i, int j) {return s[i] < s[j];}
inline bool cmp_t(int i, int j) {return t[i] < t[j];}
void dfs(int u) {
if(ecur[u]==edge[u].size())return ;
ans.push_back(edge[u][ecur[u]].second);
dfs(edge[u][ecur[u] ++].first);
}
bool solve_graph(int tot) {
ans.clear();
for (int i = 1; i <= tot; i ++) ecur[i] = 0;
dfs(1);
for (int i = 1; i <= tot; i ++)
if (ecur[i] != edge[i].size()) return false;
vi anss(0), anst(0);
for (auto x : ans)
if (x <= N) anss.push_back(x);
else anst.push_back(x - N);
for (int i = 0; i < anss.size(); i ++) printf("%d%c", anss[i], "\n "[i + 1 < M]);
for (int i = 0; i < anst.size(); i ++) printf("%d%c", anst[i], "\n "[i + 1 < M]);
return true;
}
void solve() {
scanf("%d%d", &N, &M);
for (int i = 1; i <= N; i ++) {
ids[i] = i;
idt[i] = i;
scanf("%s", str + 1);
has[i].build(str);
s[i].resize(M + 1);
s[i][0] = 0;
for (int j = 1; j <= M; j ++) s[i][j] = str[j];
}
for (int i = 1; i <= N; i ++) {
scanf("%s", str + 1);
hat[i].build(str);
t[i].resize(M + 1);
t[i][0] = 0;
for (int j = 1; j <= M; j ++) t[i][j] = str[j];
}
sort(ids + 1, ids + N + 1, cmp_s);
sort(idt + 1, idt + N + 1, cmp_t);
char flag = 1;
for (int i = 1; i <= N; i ++)
if (s[ids[i]] != t[idt[i]]) {
flag = 0; break;
}
if (flag) {
for (int i = 1; i <= N; i ++) printf("%d%c", ids[i], "\n "[i < N]);
for (int i = 1; i <= N; i ++) printf("%d%c", idt[i], "\n "[i < N]);
return ;
}
for (int i = 1; i < M; i ++) {
int tot = 0;
map <pii, int> idx;
for (int j = 1; j <= N * 4; j ++) edge[j].clear();
for (int j = 1; j <= N; j ++) {
pii sj1 = has[j].get(1, i), sj2 = has[j].get(i + 1, M);
pii tj1 = hat[j].get(1, M - i), tj2 = hat[j].get(M - i + 1, M);
#define allocate(idx, x) (idx.count(x) ? idx[x] : (idx[x] = ++ tot))
int u1 = allocate(idx, sj1), v1 = allocate(idx, sj2);
int u2 = allocate(idx, tj1), v2 = allocate(idx, tj2);
#undef allocate
edge[u1].emplace_back(v1, j);
edge[u2].emplace_back(v2, j + N);
}
if (solve_graph(tot)) {
return ;
}
}
puts("-1");
}
int main() {
//freopen("hayasa","r",stdin);
init();
int T;
scanf("%d", &T);
while (T --) solve();
return 0;
}
void init() {
pw2[0] = 1; pw1[0] = 1;
for (int i = 1; i < MAX_N; i ++) {
pw1[i] = 1ll * pw1[i - 1] * Base1 % Mod1;
pw2[i] = 1ll * pw2[i - 1] * Base2 % Mod2;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 40ms
memory: 262628kb
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: 283ms
memory: 262920kb
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 1 1 1 1 -1 -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: -100
Wrong Answer
time: 236ms
memory: 262636kb
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 -1 -1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer not cyclic isomorphism (test case 9)