QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#243692 | #7686. The Phantom Menace | zhoukangyang# | WA | 44ms | 331252kb | C++11 | 3.1kb | 2023-11-08 15:59:17 | 2023-11-08 15:59:17 |
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-09 15:33:42]
- hack成功,自动添加数据
- (//qoj.ac/hack/445)
- [2023-11-08 15:59:17]
- 提交
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) {
cout << "Yes\n";
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 << "No\n";
}
int main () {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t; cin >> t; while(t--) Main();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 44ms
memory: 331252kb
input:
2 3 3 abc ghi def bcd efg hia 1 3 abc def
output:
Yes 1 3 2 1 2 3 No
result:
wrong output format Expected integer, but "Yes" found (test case 1)