QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#245340 | #7686. The Phantom Menace | ucup-team045 | Compile Error | / | / | C++20 | 5.1kb | 2023-11-09 20:49:38 | 2024-10-07 16:35:00 |
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:35:00]
- 自动重测本题所有获得100分的提交记录
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2024-10-07 16:22:17]
- hack成功,自动添加数据
- (/hack/934)
- [2023-11-09 20:49:38]
- 提交
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<random>
#include<map>
#include<unordered_map>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const int maxn = 1e6 + 5;
static const ULL mod = (1ull << 61) - 1;
ULL power[maxn];
mt19937_64 rnd(random_device{}());
uniform_int_distribution<ULL> dist(100, mod - 1);
const ULL base = dist(rnd);
static inline ULL add(ULL a, ULL b){
a += b;
if (a >= mod) a -= mod;
return a;
}
static inline ULL mul(ULL a, ULL b){
__uint128_t c = __uint128_t(a) * b;
return add(c >> 61, c & mod);
}
ULL merge(ULL h1, ULL h2, int len2){
return add(mul(h1, power[len2]), h2);
}
void init(){
power[0] = 1;
for(int i = 1; i < maxn; i++)
power[i] = mul(power[i - 1], base);
}
ULL query(const vector<ULL> &s, int l, int r){
return add(s[r], mod - mul(s[l - 1], power[r - l + 1]));
}
vector<ULL> build(const string &s){
int sz = s.size();
vector<ULL> hashed(sz + 1);
for (int i = 0; i < sz; i++){
hashed[i + 1] = add(mul(hashed[i], base), s[i]);
}
return hashed;
}
template <typename T>
vector<ULL> build(const vector<T> &s){
int sz = s.size();
vector<ULL> hashed(sz + 1);
for (int i = 0; i < sz; i++){
hashed[i + 1] = add(mul(hashed[i], base), s[i]);
}
return hashed;
}
int lcp(const vector<ULL> &a, int l1, int r1, const vector<ULL> &b, int l2, int r2){
int len = min(r1 - l1 + 1, r2 - l2 + 1);
int l = 0, r = len;
while(l < r){
int mid = (l + r + 1) / 2;
if (query(a, l1, l1 + mid - 1) == query(b, l2, l2 + mid - 1)) l = mid;
else r = mid - 1;
}
return r;
}
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
init();
int T;
cin >> T;
while(T--){
int n, m;
cin >> n >> m;
vector<string> s1(n), s2(n);
vector<vector<ULL> > h1(n), h2(n);
for(int i = 0; i < n; i++){
cin >> s1[i];
h1[i] = build(s1[i]);
}
for(int i = 0; i < n; i++){
cin >> s2[i];
h2[i] = build(s2[i]);
}
bool ok = false;
for(int i = 0; i < m; i++){
unordered_map<ULL, int> mp1, mp2;
int idx1 = 0, idx2 = 0;
auto get1 = [&](ULL x){
if (!mp1.contains(x)){
mp1[x] = ++idx1;
}
return mp1[x];
};
auto get2 = [&](ULL x){
if (!mp2.contains(x)){
mp2[x] = ++idx2;
}
return mp2[x];
};
for(int j = 0; j < n; j++){
{
ULL hsh1 = query(h1[j], 1, i);
ULL hsh2 = query(h1[j], i + 1, m);
get1(hsh1);
get2(hsh2);
}
{
ULL hsh1 = query(h2[j], 1, m - i);
ULL hsh2 = query(h2[j], m - i + 1, m);
get2(hsh1);
get1(hsh2);
}
}
int s = idx1 + idx2;
vector<int> din(s + 1), dout(s + 1);
vector<vector<pair<int, int> > > g(s + 1);
for(int j = 0; j < n; j++){
{
ULL hsh1 = query(h1[j], 1, i);
ULL hsh2 = query(h1[j], i + 1, m);
int id1 = get1(hsh1), id2 = get2(hsh2) + idx1;
g[id1].push_back({id2, j});
dout[id1] += 1, din[id2] += 1;
}
{
ULL hsh1 = query(h2[j], 1, m - i);
ULL hsh2 = query(h2[j], m - i + 1, m);
int id1 = get2(hsh1) + idx1, id2 = get1(hsh2);
g[id1].push_back({id2, j + n});
dout[id1] += 1, din[id2] += 1;
}
}
bool flag = true;
for(int i = 1; i <= s; i++){
if (din[i] != dout[i]){
flag = false;
break;
}
}
if (!flag) continue;
vector<int> path;
auto dfs = [&](auto &&dfs, int u) -> void {
while(!g[u].empty()){
auto [to, id] = g[u].back();
g[u].pop_back();
dfs(dfs, to);
path.push_back(id);
}
};
dfs(dfs, 1);
reverse(path.begin(), path.end());
if (path.size() != 2 * n) continue;
for(int i = 0; i < 2 * n; i += 2){
cout << path[i] + 1 << ' ';
}
cout << '\n';
for(int i = 1; i < 2 * n; i += 2){
cout << path[i] + 1 - n << ' ';
}
cout << '\n';
ok = true;
break;
}
if (!ok) cout << -1 << '\n';
}
}
Details
answer.code: In function ‘int main()’: answer.code:173:13: error: ‘reverse’ was not declared in this scope 173 | reverse(path.begin(), path.end()); | ^~~~~~~