QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#445 | #243693 | #7686. The Phantom Menace | rascalrabbit | zhoukangyang | Success! | 2023-11-09 15:33:13 | 2023-11-09 15:33:15 |
Details
Extra Test:
Wrong Answer
time: 40ms
memory: 331144kb
input:
10 3 4 cddd ecdd adee abee cbbb cacd 1 1 c e 3 1 d c d a c e 4 2 ea ba cc de ba ac ac ba 3 4 abcb caae bdac cece eacc cbcc 3 1 c c c b c e 4 1 b e d a b a a d 2 2 be ae ca ea 2 2 ce cc be ce 1 1 c c
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
result:
wrong answer Jury has the answer but participant has not (test case 10)
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#243693 | #7686. The Phantom Menace | zhoukangyang# | WA | 503ms | 541432kb | C++11 | 3.1kb | 2023-11-08 15:59:43 | 2024-10-13 19:41:01 |
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector <int>
#define sz(a) ((int) (a).size())
#define me(f, x) memset(f, x, sizeof(f))
#define uint unsigned int
#define ull unsigned long long
#define i128 __int128
using namespace std;
const int N = 1 << 21;
const ll mod = (ll) 998244353 * 1019260817, base = 19491001;
int n, m;
string A[N], B[N];
vector < ll > prea[N], sufa[N], preb[N], sufb[N];
ll Mul(ll a, ll b) {
return (__int128) a * b % mod;
}
ll Add(ll a, ll b) {
return (a + b) % mod;
}
ll Dec(ll a, ll b) {
return (a + mod - b) % mod;
}
ll pw[N];
void getpre(string &s, vector < ll > &pre) {
pre.resize(m + 2);
pre[0] = 0;
L(i, 1, sz(s))
pre[i] = Add(pre[i - 1], Mul(s[i - 1] - 'a' + 1, pw[i - 1]));
}
void getsuf(string &s, vector < ll > &suf) {
suf.resize(m + 2);
ll ns = 0;
R(i, sz(s), 1)
ns = Add(Mul(ns, base), s[i - 1] - 'a' + 1), suf[i] = ns;
}
unordered_map < ll, int > mp;
int tot;
ll val[N];
int f[N], deg[N];
int getid(ll x) {
if(!mp.count(x)) {
++tot;
f[tot] = tot;
val[tot] = x;
return mp[x] = tot;
} else return mp[x];
}
int ehd[N], ev[N], enx[N], eid;
int vis[N], stk[N], tp;
void eadd(int u, int v) {
++eid, ev[eid] = v, enx[eid] = ehd[u], ehd[u] = eid, vis[eid] = 0;
}
inline int find(int x) {
return f[x] == x ? x : f[x] = find(f[x]);
}
void link(int u, int v) {
++deg[u];
--deg[v];
f[find(u)] = find(v);
eadd(u, v);
}
inline void dfs(int x) {
for(int &i = ehd[x], o; i; i = enx[i]) if(!vis[i])
o = i, vis[o] = true, dfs(ev[o]), stk[++tp] = o;
}
void clear() {
L(i, 1, tot) {
ehd[i] = 0, deg[i] = 0;
}
eid = 0;
}
void Main() {
cin >> n >> m;
pw[0] = 1;
L(i, 1, m) pw[i] = Mul(pw[i - 1], base);
L(i, 1, n) {
cin >> A[i];
getpre(A[i], prea[i]);
getsuf(A[i], sufa[i]);
}
L(i, 1, n) {
cin >> B[i];
getpre(B[i], preb[i]);
getsuf(B[i], sufb[i]);
}
L(c, 0, m - 1) {
tot = 0;
eid = 0;
mp.clear();
L(i, 1, n) {
int u = getid(prea[i][c]), v = getid(sufa[i][c + 1] + mod);
link(u, v);
// cout << u << " -> " << v << ' ' << prea[i][c] << " " << sufa[i][c + 1] << '\n';
}
L(i, 1, n) {
int u = getid(preb[i][m - c] + mod), v = getid(sufb[i][m - c + 1]);
// cout << u << " -> " << v << ' ' <<
// preb[i][m - c] << ' ' << sufb[i][m - c + 1] << '\n';
link(u, v);
}
int win = 1;
L(i, 1, tot) if(deg[i]) {
win = 0;
}
L(i, 1, tot) if(find(i) != find(1)) {
win = 0;
}
if(win) {
tp = 0;
dfs(1);
vi A, B;
R(i, tp, 1) {
if(stk[i] > n)
B.emplace_back(stk[i] - n);
else
A.emplace_back(stk[i]);
}
for(auto u : A)
cout << u << ' ';
cout << '\n';
for(auto u : B)
cout << u << ' ';
cout << '\n';
clear();
return ;
} else {
clear();
}
// prea[i][c] -> sufa[i][c + 1]
// preb[i][m - c] -> sufb[i][m - c + 1]
}
cout << "-1\n";
}
int main () {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t; cin >> t; while(t--) Main();
return 0;
}