Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
52378 | _ | 修复符文 | C++ | 通过 | 100 | 60 MS | 456 KB | 2518 | 2022-07-19 12:04:18 |
#include <bits/stdc++.h> using namespace std; const int MXN = 500005; const int RDX = 26; const int MOD1 = 998244353; const int MOD2 = 1000000007; const char DIFF = 'a'; int thsv1, thsv2, chsv1, chsv2; char tgt[MXN], cur[MXN]; int gcd(int a, int b) { while (b) { int temp(b); b = a % b; a = temp; } return a; } int pw(int b, int p, int m) { int ans(1); while (p) { if (p & 1) ans = ans * 1LL * b % m; b = b * 1LL * b % m; p >>= 1; } return ans % m; } int strhs(char str[], int len, int mod) { int ans(0); for (int i(0); i != len; ++i) { ans = (ans * 1LL * RDX % mod + (str[i] - DIFF)) % mod; } return ans; } int main() { // freopen("runes.in", "r", stdin); // freopen("runes.out", "w", stdout); int T(0); cin >> T; while (T--) { int A(0), B(0); cin >> cur >> tgt >> A >> B; bool able(false); if (A < B) swap(A, B); int N = strlen(tgt); int L = gcd(N, A - B); int pw1(pw(RDX, N - 1, MOD1)), pw2(pw(RDX, N - 1, MOD2)); thsv1 = strhs(tgt, N, MOD1), thsv2 = strhs(tgt, N, MOD2); chsv1 = strhs(cur, N, MOD1), chsv2 = strhs(cur, N, MOD2); // cout << L << ' ' << thsv1 << ',' << thsv2 << ' ' << pw1 << ',' << pw2 << endl; for (int i(0); !able && i != N; ++i) { // cout << chsv1 << ' ' << chsv2 << endl; if (i % L == 0 && chsv1 == thsv1 && chsv2 == thsv2) { able = true; } chsv1 = ((chsv1 - (cur[i] - DIFF) * 1LL * pw1 % MOD1 + MOD1) % MOD1 * 1LL * RDX % MOD1 + (cur[i] - DIFF)) % MOD1; chsv2 = ((chsv2 - (cur[i] - DIFF) * 1LL * pw2 % MOD2 + MOD2) % MOD2 * 1LL * RDX % MOD2 + (cur[i] - DIFF)) % MOD2; } for (int i(0); i < A - i - 1; ++i) swap(tgt[i], tgt[A - i - 1]); for (int i(A); i < N - (i - A) - 1; ++i) swap(tgt[i], tgt[N - (i - A) - 1]); thsv1 = strhs(tgt, N, MOD1), thsv2 = strhs(tgt, N, MOD2); chsv1 = strhs(cur, N, MOD1), chsv2 = strhs(cur, N, MOD2); // cout << L << ' ' << thsv1 << ',' << thsv2 << ' ' << pw1 << ',' << pw2 << endl; for (int i(0); !able && i != N; ++i) { // cout << chsv1 << ' ' << chsv2 << endl; if (i % L == 0 && chsv1 == thsv1 && chsv2 == thsv2) { able = true; } chsv1 = ((chsv1 - (cur[i] - DIFF) * 1LL * pw1 % MOD1 + MOD1) % MOD1 * 1LL * RDX % MOD1 + (cur[i] - DIFF)) % MOD1; chsv2 = ((chsv2 - (cur[i] - DIFF) * 1LL * pw2 % MOD2 + MOD2) % MOD2 * 1LL * RDX % MOD2 + (cur[i] - DIFF)) % MOD2; } puts(able ? "yes" : "no"); } return 0; }