QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#297054 | #7686. The Phantom Menace | yllcm | WA | 22ms | 142140kb | C++14 | 2.5kb | 2024-01-03 21:48:07 | 2024-01-03 21:48:07 |
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-01-03 21:48:07]
- 提交
answer
#include<bits/stdc++.h>
#define ll long long
#define db double
#define ull unsigned long long
#define pb push_back
#define pii pair<int, int>
#define FR first
#define SE second
using namespace std;
inline int read() {
int x = 0; bool op = false;
char c = getchar();
while(!isdigit(c))op |= (c == '-'), c = getchar();
while(isdigit(c))x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return op ? -x : x;
}
const int N = 1e6 + 10;
const int B = 131;
int n, m;
int pw[N];
string s[N], t[N];
vector<ull> hss[N], hst[N];
int pre(int x, int y, int o) {
if(o == 0)return hss[x][y];
else return hst[x][y];
}
int suf(int x, int y, int o) {
if(o == 0)return hss[x][m] - hss[x][y - 1] * pw[m - y + 1];
else return hst[x][m] - hst[x][y - 1] * pw[m - y + 1];
}
int in[N], hd[N];
vector<pii> G[N];
vector<int> Eu;
void dfs(int u) {
for(int i = hd[u]; i < G[u].size(); i = hd[u]) {
pii e = G[u][i]; hd[u] = i + 1;
dfs(e.FR); Eu.pb(e.SE);
}
return ;
}
bool chk(int p) {
int tot = 0;
unordered_map<ull, int> tb1, tb2;
for(int i = 1; i <= n; i++) {
ull hp = pre(i, p, 0), hs = suf(i, p + 1, 0);
if(!tb1.count(hp))tb1[hp] = ++tot, vector<pii>().swap(G[tot]), in[tot] = 0;
if(!tb2.count(hs))tb2[hp] = ++tot, vector<pii>().swap(G[tot]), in[tot] = 0;
G[tb1[hp]].pb({tb2[hs], i}); in[tb2[hs]]++;
}
for(int i = 1; i <= n; i++) {
ull hp = pre(i, m - p, 0), hs = suf(i, m - p + 1, 0);
if(!tb2.count(hp))tb1[hp] = ++tot, vector<pii>().swap(G[tot]), in[tot] = 0;
if(!tb1.count(hs))tb2[hp] = ++tot, vector<pii>().swap(G[tot]), in[tot] = 0;
G[tb2[hp]].pb({tb1[hs], i + n}); in[tb1[hs]]++;
}
for(int i = 1; i <= tot; i++)if(in[i] != G[i].size())return false;
vector<int>().swap(Eu);
dfs(1);
if(Eu.size() != n * 2)return false;
reverse(Eu.begin(), Eu.end());
for(int x : Eu)if(x <= n)printf("%d ", x); putchar('\n');
for(int x : Eu)if(x > n)printf("%d ", x - n); putchar('\n');
return true;
}
void solve() {
n = read(); m = read();
for(int i = 1; i <= n; i++)cin >> s[i];
for(int i = 1; i <= n; i++)cin >> t[i];
for(int i = 1; i <= n; i++) {
hss[i].resize(m + 1); hst[i].resize(m + 1);
for(int j = 0; j < m; j++) {
hss[i][j + 1] = hss[i][j] * B + s[i][j];
hst[i][j + 1] = hst[i][j] * B + t[i][j];
}
}
for(int i = 1; i <= m; i++)if(chk(i))return ;
puts("-1");
return ;
}
int main() {
pw[0] = 1;
for(int i = 1; i < N; i++)pw[i] = pw[i - 1] * B;
int test = read();
while(test--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 22ms
memory: 142140kb
input:
2 3 3 abc ghi def bcd efg hia 1 3 abc def
output:
1 2 3 2 3 1 -1
result:
wrong answer not cyclic isomorphism (test case 1)