QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#165591#6851. Cyclically IsomorphicPPP#AC ✓46ms8100kbC++172.0kb2023-09-05 19:37:282023-09-05 19:37:28

Judging History

你现在查看的是最新测评结果

  • [2023-09-05 19:37:28]
  • 评测
  • 测评结果:AC
  • 用时:46ms
  • 内存:8100kb
  • [2023-09-05 19:37:28]
  • 提交

answer

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n, m;
const int mod[2] = {998244353, (int)1e9 + 7};
int sum(int a, int b, int mod) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int sub(int a, int b, int mod) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}
int mult(int a, int b, int mod) {
    return (1LL * a * b) % mod;
}
const int pt = 239;
const int maxN = 2e5 + 10;
int pw[2][maxN];
int pref[2][maxN];
pair<int,int> tp[maxN];
void build(string& s, int id) {
    string t = s + s;
    int n = t.size();
    for (int j = 0; j < 2; j++) {
        pw[j][0] = 1;
        for (int i = 1; i <= n; i++) {
            pw[j][i] = mult(pt, pw[j][i - 1], mod[j]);
        }
    }
    for (int j = 0; j < 2; j++) {
        pref[j][0] = 0;
        for (int i = 1; i <= n; i++) {
            pref[j][i] = sum(mult(pt, pref[j][i - 1], mod[j]), (t[i - 1] - 'a' + 1), mod[j]);
        }
    }
    pair<int,int> mn = {INT_MAX, INT_MAX};
    for (int st = 0; st < s.size(); st++) {
        int D[2] = {0, 0};
        for (int z = 0; z < 2; z++) {
            D[z] = sub(pref[z][st + s.size()], mult(pw[z][s.size()], pref[z][st], mod[z]), mod[z]);
        }
        mn = min(mn, make_pair(D[0], D[1]));
    }
    tp[id] = mn;
}
void solve() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        build(s, i);
    }
    int q;
    cin >> q;
    while (q--) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        if (tp[x] == tp[y]) {
            cout << "Yes\n";
        }
        else {
            cout << "No\n";
        }
    }

}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    int tst;
    cin >> tst;
    while (tst--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 46ms
memory: 8100kb

input:

5
10 10000
afcadffafeeebdfedfdafecfdbeecbcadfedcffaedecbacffedeccacfcbfbbdbcefbdefefebcbeacfbaafddbabcbfaeddaaefebbddafaaaaaedcbbdaafaffcbeeebfbbeedebabfbdbaceabfcccfedbdeafccbaffdeadbefbfeadbbedeeabbaafebaceeaeedbaddfecdefaabdbcfadadaebbdeedcfeeabbbdbcefdadbeecafcabbddddbcacadbbcddeddbbeecbdadefbaa...

output:

No
No
No
Yes
Yes
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
Yes
No
No
No
No
No
No
No
No
Yes
No
Yes
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
Yes
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
Yes
No
Yes
No
Yes
No
No
No
No
No
No
No
No
Yes
Yes
Ye...

result:

ok 500000 lines