QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#237503 | #7686. The Phantom Menace | ucup-team027# | Compile Error | / | / | C++23 | 4.7kb | 2023-11-04 14:18:20 | 2023-11-04 14:18:20 |
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-04 14:18:20]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-11-04 14:18:20]
- 提交
answer
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
struct H {
typedef uint64_t ull;
ull x; H(ull x=0) : x(x) {}
#define OP(O,A,B) H operator O(H o) { ull r = x; asm \
(A "addq %%rdx, %0\n adcq $0,%0" : "+a"(r) : B); return r; }
OP(+,,"d"(o.x)) OP(*,"mul %1\n", "r"(o.x) : "rdx")
H operator-(H o) { return *this + ~o.x; }
ull get() const { return x + !~x; }
bool operator==(H o) const { return get() == o.get(); }
bool operator<(H o) const { return get() < o.get(); }
};
static const H C = (ll)1e11+3; // (order ~ 3e9; random also ok)
struct HashInterval {
vector<H> ha, pw;
HashInterval(string& str) : ha(sz(str)+1), pw(ha) {
pw[0] = 1;
rep(i,0,sz(str))
ha[i+1] = ha[i] * C + str[i],
pw[i+1] = pw[i] * C;
}
H hashInterval(int a, int b) { // hash [a, b)
return ha[b] - ha[a] * pw[b - a];
}
};
H hashString(string& s){H h{}; for(char c:s) h=h*C+c;return h;}
// end of hash
bool zeroCyc(vector<string> a, vector<string> b) {
vector<pair<string, int>> pa, pb;
for (int i = 0; i < n; i++) {
pa.emplace_back(a[i], i);
pb.emplace_back(b[i], i);
}
sort(all(pa)); sort(all(pb));
for (int i = 0; i < n; i++) {
if (pa[i].first != pb[i].first) return 0;
}
for (int i = 0; i < n; i++) {
cout << pa[i].second+1 << ' ';
}
cout << '\n';
for (int i = 0; i < n; i++) {
cout << pb[i].second+1 << ' ';
}
cout << '\n';
return 1;
}
// end of case
vi eulerWalk(vector<vector<pii>>& gr, int nedges, int src=0) {
int n = sz(gr);
vi D(n), its(n), eu(nedges), ret, s = {src};
D[src]++; // to allow Euler paths, not just cycles
while (!s.empty()) {
int x = s.back(), y, e, &it = its[x], end = sz(gr[x]);
if (it == end){ ret.push_back(x); s.pop_back(); continue; }
tie(y, e) = gr[x][it++];
if (!eu[e]) {
D[x]--, D[y]++;
eu[e] = 1; s.push_back(y);
}}
for (int x : D) if (x < 0 || sz(ret) != nedges+1) return {};
return {ret.rbegin(), ret.rend()};
}
// end of euler walk
void solve() {
int n, m; cin >> n >> m;
vector<string> a(n), b(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
if (zeroCyc(a, b)) {
return;
}
vector<HashInterval> hsa, hsb;
for (int i = 0; i < n; i++) {
hsa.push_back(HashInterval(a[i]));
hsb.push_back(HashInterval(b[i]));
}
//cout << hsb[0].hashInterval(0, 2).x << '\n';
//cout << hsa[0].hashInterval(1, 3).x << '\n';
for (int i = 1, j = m-1; i < m; i++, j--) {\
//cout << "Cutting " << i << '\n';
// A-prefix: [0, i) --> forward edges
// B-suffix: [j, m) --> backward edges
int idx = 0;
map<pair<H, int>, int> nds;
vector<tuple<int, int, int>> edges;
for (int k = 0; k < n; k++) {
H l = hsa[k].hashInterval(0, i);
H r = hsa[k].hashInterval(i, m);
if (nds.count({l, 0}) == 0) {
nds[{l, 0}] = idx;
idx++;
}
if (nds.count({r, 1}) == 0) {
nds[{r, 1}] = idx;
idx++;
}
edges.emplace_back(nds[{l, 0}], nds[{r, 1}], k);
}
for (int k = 0; k < n; k++) {
H l = hsb[k].hashInterval(j, m);
H r = hsb[k].hashInterval(0, j);
if (nds.count({l, 0}) == 0) {
nds[{l, 0}] = idx;
idx++;
}
if (nds.count({r, 1}) == 0) {
nds[{r, 1}] = idx;
idx++;
}
edges.emplace_back(nds[{r, 1}], nds[{l, 0}], k+n);
}
vector<vector<pii>> gr(idx);
for (auto [u, v, id]: edges) {
//cout << "EDGE " << u << ' ' << v << ' ' << id << '\n';
gr[u].emplace_back(v, id);
}
//cout << '\n';
vi res = eulerWalk(gr, edges.size(), 0);
if (res.empty()) continue;
else {
/*
cout << "Found euler path\n";
for (int k: res) cout << k << ' ';
cout << '\n';
*/
// found answer
map<pair<int, int>, vector<int>> eds;
for (auto [u, v, id]: edges) {
eds[{u, v}].push_back(id);
}
vector<int> p1, p2;
for (int k = 1; k < res.size(); k++) {
int u = res[k-1], v = res[k];
int edid = eds[{u, v}].back();
eds[{u, v}].pop_back();
if (edid < n) p1.push_back(edid);
else p2.push_back(edid-n);
}
for (int k: p1) cout << k+1 << ' ';
cout << '\n';
for (int k: p2) cout << k+1 << ' ';
cout << '\n';
return;
}
}
cout << "-1\n";
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
cin.exceptions(cin.failbit);
int t; cin >> t;
while (t--) {
solve();
}
return 0;
}
详细
answer.code: In function ‘bool zeroCyc(std::vector<std::__cxx11::basic_string<char> >, std::vector<std::__cxx11::basic_string<char> >)’: answer.code:46:29: error: ‘n’ was not declared in this scope 46 | for (int i = 0; i < n; i++) { | ^ answer.code:52:29: error: ‘n’ was not declared in this scope 52 | for (int i = 0; i < n; i++) { | ^ answer.code:55:29: error: ‘n’ was not declared in this scope 55 | for (int i = 0; i < n; i++) { | ^ answer.code:59:29: error: ‘n’ was not declared in this scope 59 | for (int i = 0; i < n; i++) { | ^