QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#244152 | #7686. The Phantom Menace | ikefumy | WA | 933ms | 3492kb | C++20 | 5.9kb | 2023-11-08 21:37:41 | 2023-11-08 21:37:42 |
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 21:37:41]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define int128 __int128_t
#define pii128 pair<int128,int128>
const int inf = 1 << 30;
const ll linf = 1e18;
const ll mod = 1e9 + 7;
const db EPS = 1e-10;
const db pi = acos(-1);
template<class T> bool chmin(T& x, T y){
if(x > y) {
x = y;
return true;
} else return false;
}
template<class T> bool chmax(T& x, T y){
if(x < y) {
x = y;
return true;
} else return false;
}
// overload macro
#define CAT( A, B ) A ## B
#define SELECT( NAME, NUM ) CAT( NAME, NUM )
#define GET_COUNT( _1, _2, _3, _4, _5, _6 /* ad nauseam */, COUNT, ... ) COUNT
#define VA_SIZE( ... ) GET_COUNT( __VA_ARGS__, 6, 5, 4, 3, 2, 1 )
#define VA_SELECT( NAME, ... ) SELECT( NAME, VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)
// rep(overload)
#define rep( ... ) VA_SELECT(rep, __VA_ARGS__)
#define rep2(i, n) for (int i = 0; i < int(n); i++)
#define rep3(i, a, b) for (int i = a; i < int(b); i++)
#define rep4(i, a, b, c) for (int i = a; i < int(b); i += c)
// repll(overload)
#define repll( ... ) VA_SELECT(repll, __VA_ARGS__)
#define repll2(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repll3(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define repll4(i, a, b, c) for (ll i = a; i < (ll)(b); i += c)
// rrep(overload)
#define rrep( ... ) VA_SELECT(rrep, __VA_ARGS__)
#define rrep2(i, n) for (int i = n - 1; i >= 0; i--)
#define rrep3(i, a, b) for (int i = b - 1; i >= a; i--)
#define rrep4(i, a, b, c) for (int i = b - 1; i >= a; i -= c)
// rrepll(overload)
#define rrepll( ... ) VA_SELECT(rrepll, __VA_ARGS__)
#define rrepll2(i, n) for (ll i = (ll)(n) - 1; i >= 0ll; i--)
#define rrepll3(i, a, b) for (ll i = b - 1; i >= (ll)(a); i--)
#define rrepll4(i, a, b, c) for (ll i = b - 1; i >= (ll)(a); i -= c)
// for_earh
#define fore(e, v) for (auto&& e : v)
// vector
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
random_device rnd;
mt19937 mt(rnd());
struct rolling_hash {
private:
static inline const ll base = mt() + 2;
static const ll MASK30 = (1ll << 30) - 1;
static const ll MASK31 = (1ll << 31) - 1;
static const ll HASH_MOD = (1ll << 61) - 1;
static const ll MASK61 = HASH_MOD;
ll calc_mod(ll x) {
ll xu = x >> 61;
ll xl = x & MASK61;
ll ret = xu + xl;
if (ret >= HASH_MOD) ret -= HASH_MOD;
return ret;
}
ll calc_mul(ll a, ll b) {
ll au = a >> 31;
ll al = a & MASK31;
ll bu = b >> 31;
ll bl = b & MASK31;
ll mid = al * bu + au * bl;
ll midu = mid >> 30;
ll midl = mid & MASK30;
return calc_mod(au * bu * 2 + midu + (midl << 31) + al * bl);
}
public:
int N;
string S;
vector<ll> hash, power;
rolling_hash(){}
rolling_hash(string s) : N(s.size()), S(s), hash(N + 1), power(N + 1) {
power[0] = 1, hash[0] = S[0];
for (int i = 0; i < N; i++) {
power[i + 1] = calc_mul(power[i], base);
hash[i + 1] = calc_mod(calc_mul(hash[i], base) + s[i]);
}
}
ll get_hash(int l = 0, int r = -1) {
if (r == -1) r = N;
return calc_mod(hash[r] - calc_mul(hash[l], power[r - l]) + HASH_MOD);
}
};
void solve() {
int n, m;
cin >> n >> m;
vector<string> A(n), B(n);
vector<rolling_hash> arh(n), brh(n);
rep (i, n) cin >> A[i], arh[i] = rolling_hash(A[i]);
rep (i, n) cin >> B[i], brh[i] = rolling_hash(B[i]);
bool flag = false;
vector<int> pa(n), pb(n);
auto judge = [&](int sh) {
map<ll, int> na, nb;
vector<vector<pii>> G(4 * n);
vector<int> itr(4 * n);
// 各hash値に番号を割り当てる
auto make_node = [](map<ll, int>& nv, vector<rolling_hash>& rh, int sh, int& idx) {
rep (i, rh.size()) {
ll preh = rh[i].get_hash(0, sh);
ll posh = rh[i].get_hash(sh);
if (nv.find(preh) == nv.end()) nv[preh] = idx++;
if (nv.find(posh) == nv.end()) nv[posh] = idx++;
}
};
int idx = 0;
make_node(na, arh, sh, idx);
make_node(nb, brh, m - sh, idx);
// 辺をはる
auto make_edge = [&](map<ll, int>& nv, map<ll, int>& nu, vector<rolling_hash>& rh, int sh) -> bool {
rep (i, rh.size()) {
ll preh = rh[i].get_hash(0, sh);
ll posh = rh[i].get_hash(sh);
if (nu.find(posh) == nu.end()) return false;
G[nv[preh]].emplace_back(nv[posh], i);
G[nv[posh]].emplace_back(nu[posh], -1);
}
return true;
};
if (!make_edge(na, nb, arh, sh)) return;
if (!make_edge(nb, na, brh, m - sh)) return;
int v = 0;
vector<int> path;
while (true) {
if (itr[v] == (int)G[v].size()) break;
path.push_back(G[v][itr[v]].second);
v = G[v][itr[v]++].first;
}
int st = 0;
vector<vector<int>> ans(2);
fore (u, path) {
if (u == -1) continue;
ans[st].push_back(u);
st ^= 1;
}
if (ans[0].size() == ans[1].size() && (int)ans[0].size() == n) pa = ans[0], pb = ans[1], flag = true;
};
rep (i, m) {
judge(i);
}
if (flag) {
fore (u, pa) cout << u + 1 << ' ';
cout << '\n';
fore (u, pb) cout << u + 1 << ' ';
cout << '\n';
} else {
cout << -1 << endl;
}
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
int t;
cin >> t;
while (t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3492kb
input:
2 3 3 abc ghi def bcd efg hia 1 3 abc def
output:
1 3 2 1 2 3 -1
result:
ok 2 cases (2 test cases)
Test #2:
score: 0
Accepted
time: 933ms
memory: 3492kb
input:
1000000 1 1 b b 1 1 a b 1 1 b a 1 1 a a 1 1 b b 1 1 a b 1 1 b a 1 1 a a 1 1 b b 1 1 a b 1 1 b a 1 1 a a 1 1 b b 1 1 a b 1 1 b a 1 1 a a 1 1 b b 1 1 a b 1 1 b a 1 1 a a 1 1 b b 1 1 a b 1 1 b a 1 1 a a 1 1 b b 1 1 a b 1 1 b a 1 1 a a 1 1 b b 1 1 a b 1 1 b a 1 1 a a 1 1 b b 1 1 a b 1 1 b a 1 1 a a 1 1 ...
output:
1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 1 1 1 1 -1 -1 ...
result:
ok 1000000 cases (1000000 test cases)
Test #3:
score: -100
Wrong Answer
time: 574ms
memory: 3436kb
input:
500000 1 2 dd ba 1 2 cd ba 1 2 bd ba 1 2 ad ba 1 2 dc ba 1 2 cc ba 1 2 bc ba 1 2 ac ba 1 2 db ba 1 2 cb ba 1 2 bb ba 1 2 ab ba 1 2 da ba 1 2 ca ba 1 2 ba ba 1 2 aa ba 1 2 dd aa 1 2 cd aa 1 2 bd aa 1 2 ad aa 1 2 dc aa 1 2 cc aa 1 2 bc aa 1 2 ac aa 1 2 db aa 1 2 cb aa 1 2 bb aa 1 2 ab aa 1 2 da aa 1 2...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 -1 ...
result:
wrong answer not cyclic isomorphism (test case 29)