QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#394879 | #7686. The Phantom Menace | ucup-team228# | WA | 0ms | 34976kb | C++20 | 7.3kb | 2024-04-20 21:08:18 | 2024-04-20 21:08:19 |
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-04-20 21:08:18]
- 提交
answer
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2") // doesn't work on Yandex
//#pragma GCC target("avx") // for old judges
//#pragma GCC target("bmi,bmi2,lzcnt,popcnt") // fast bit operations
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <chrono>
#include <random>
#include <string>
#include <numeric>
#include <complex>
#include <tuple>
#include <utility>
#include <bitset>
#include <array>
#include <stack>
#include <sstream>
#include <unordered_set>
using namespace std;
typedef long long ll;
string to_string(string a) { return '"' + a + '"'; }
string to_string(char a) { return "'" + string(1, a) + "'"; }
string to_string(const char* a) { return to_string((string) a); }
string to_string(bool a) { return a ? "true" : "false"; }
template <class T1, class T2>
string to_string(pair<T1, T2> a) {
return "(" + to_string(a.first) + ", " + to_string(a.second) + ")";
}
template <class T>
string to_string(T a) {
bool first = true; string res = "{";
for (const auto& i : a) {
if (!first) res += ", ";
first = false;
res += to_string(i);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <class T1, class... T2>
void debug_out(T1 a, T2... b) {
cerr << " " << to_string(a);
debug_out(b...);
}
#ifdef LOCAL
#define out(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define out(...) 42
#endif
clock_t start_time; void start_timer() { start_time = clock(); }
double get_time() { return (double) (clock() - start_time) / CLOCKS_PER_SEC; }
void Solve();
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
freopen("usr/share/man/man1/input.txt", "r", stdin);
#endif
start_timer();
Solve();
#ifdef LOCAL
cerr << fixed << setprecision(3);
cerr << endl << "Time spent: " << get_time() << endl;
#endif
return 0;
}
// do something, stay focused
// look for stupid bugs
// guess, slow, stress
// don't overgeneralize
// don't rush
// don't waste time on standings
// SOLVE THE PROBLEM OR DIE TRYING
// THE SOLUTION IS ALWAYS SIMPLE
// THE CODE IS ALWAYS SHORT
template <int mod>
struct Modular {
int val;
Modular(int _val = 0) : val(_val) {}
friend Modular operator+(const Modular& a, const Modular& b) {
return a.val + b.val >= mod ? a.val + b.val - mod : a.val + b.val;
}
friend Modular operator-(const Modular& a, const Modular& b) {
return a.val - b.val < 0 ? a.val - b.val + mod : a.val - b.val;
}
friend Modular operator*(const Modular& a, const Modular& b) {
return int(1ll * a.val * b.val % mod);
}
};
mt19937 rnd;
template <int mod>
struct PolyHash {
using Mint = Modular<mod>;
static const int N = 1e6 + 10;
Mint base = rnd() % 10000 + 1000;
Mint pw[N];
Mint pref[N];
void init(const string& s) {
int n = (int) s.size();
pw[0] = 1;
pref[0] = 0;
for (int i = 1; i <= n; i++) {
pw[i] = pw[i - 1] * base;
pref[i] = pref[i - 1] * base + (s[i - 1] - 'a');
}
}
Mint get(int l, int r) {
l++;
r++;
return pref[r] - pref[l - 1] * pw[r - l + 1];
}
};
const int mod1 = 1e9 + 7;
const int mod2 = 1e9 + 9;
PolyHash<mod1> h1[2];
PolyHash<mod2> h2[2];
//PolyHash<mod3> h3[2];
ll get_hash(int i, int l, int r) {
ll x = h1[i].get(l, r).val;
ll y = h2[i].get(l, r).val;
return (x << 30) | y;
}
vector<pair<string, int>> a[2];
string A[2];
vector<pair<ll, ll>> h[2];
vector<ll> us[2];
vector<ll> vs[2];
vector<vector<pair<int, int>>> g;
vector<int> cycle;
vector<int> ptr;
vector<int> ans[2];
void dfs(int v) {
if (ptr[v] == g[v].size()) {
return;
}
auto [u, e] = g[v][ptr[v]];
ptr[v]++;
dfs(u);
cycle.push_back(e);
}
bool sol() {
int n, m;
cin >> n >> m;
for (int j = 0; j <= 1; j++) {
a[j].assign(n, {"", 0});
A[j].clear();
for (int i = 0; i < n; i++) {
cin >> a[j][i].first;
a[j][i].second = i;
}
sort(a[j].begin(), a[j].end());
}
bool are_eq = 1;
for (int i = 0; i < n; i++) {
if (a[0][i].first != a[1][i].first) {
are_eq = 0;
}
A[0] += a[0][i].first;
A[1] += a[1][i].first;
}
if (are_eq) {
for (int i = 0; i < n; i++) {
cout << a[0][i].second + 1 << " ";
}
cout << "\n";
for (int i = 0; i < n; i++) {
cout << a[1][i].second + 1 << " ";
}
cout << "\n";
return 1;
}
for (int j = 0; j <= 1; j++) {
h1[j].init(A[j]);
h2[j].init(A[j]);
}
for (int shift = 1; shift < m; shift++) {
for (int j = 0; j <= 1; j++) {
h[j].assign(n, {0, 0});
us[j].clear();
vs[j].clear();
int s = j == 0 ? shift : m - shift;
for (int i = 0; i < n; i++) {
ll h_u = get_hash(j, i * m, i * m + s - 1);
ll h_v = get_hash(j, i * m + s, (i + 1) * m - 1);
if (j == 1) {
swap(h_u, h_v);
}
h[j][i] = {h_u, h_v};
us[j].push_back(h_u);
vs[j].push_back(h_v);
}
sort(us[j].begin(), us[j].end());
sort(vs[j].begin(), vs[j].end());
}
if ((us[0] != us[1]) || (vs[0] != vs[1])) {
continue;
}
us[0].erase(unique(us[0].begin(), us[0].end()), us[0].end());
vs[0].erase(unique(vs[0].begin(), vs[0].end()), vs[0].end());
int cnt_us = (int) us[0].size();
int cnt_vs = (int) vs[0].size();
g.assign(cnt_us + cnt_vs, {});
for (int j = 0; j <= 1; j++) {
for (int i = 0; i < n; i++) {
auto [h_u, h_v] = h[j][i];
int u = (int) (lower_bound(us[0].begin(), us[0].end(), h_u) - us[0].begin());
int v = (int) (lower_bound(vs[0].begin(), vs[0].end(), h_v) - vs[0].begin());
int id = a[j][i].second;
if (j == 0) {
g[u].push_back({v + cnt_us, id});
}
else {
g[v + cnt_us].push_back({u, id});
}
}
}
cycle.clear();
ptr.assign(g.size(), 0);
dfs(0);
if (cycle.size() != 2 * n) {
continue;
}
reverse(cycle.begin(), cycle.end());
ans[0].clear();
ans[1].clear();
for (int i = 0; i < 2 * n; i++) {
ans[i % 2].push_back(cycle[i]);
}
for (int i : ans[0]) {
cout << i + 1 << " ";
}
cout << "\n";
for (int i : ans[1]) {
cout << i + 1 << " ";
}
cout << "\n";
return 1;
}
return 0;
}
void Solve() {
int T;
cin >> T;
while (T--) {
bool ans = sol();
if (!ans) {
cout << "-1\n";
}
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 34976kb
input:
2 3 3 abc ghi def bcd efg hia 1 3 abc def
output:
-1 -1
result:
wrong answer Jury has the answer but participant has not (test case 1)