QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#141996#6851. Cyclically IsomorphicsupepapupuAC ✓30ms7108kbC++171.4kb2023-08-18 09:59:072023-08-18 09:59:10

Judging History

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

  • [2023-08-18 09:59:10]
  • 评测
  • 测评结果:AC
  • 用时:30ms
  • 内存:7108kb
  • [2023-08-18 09:59:07]
  • 提交

answer

#include <bits/stdc++.h>

#define x first
#define y second
#define el '\n'
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 10, INF = 0x3f3f3f3f, mod = 998244353;
const int base = 149;

inline int read() {
    int f = 1, k = 0;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        k = k * 10 + c - '0';
        c = getchar();
    }
    return f * k;
}

string s[N];
ll hs[N];

ll get_min(string s) {
    int n = s.size();
    s = s + s;
    int i = 0, j = 1;
    while (i < n && j < n) {
        int k = 0;
        while (k < n && s[i + k] == s[j + k]) ++k;
        if (k == n) break;
        if (s[i + k] > s[j + k]) i += k + 1;
        else j += k + 1;
        if (i == j) ++j;
    }
    int k = min(i, j);
    ll res = 0;
    for (int i = k; i < k + n; ++i) {
        res *= base;
        res += s[i];
    }
    return res;
}

void solve() {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cin >> s[i];
        hs[i] = get_min(s[i]);
    }
    int Q;
    cin >> Q;
    while (Q--) {
        int a, b;
        cin >> a >> b;
        if (hs[a] == hs[b]) puts("Yes");
        else puts("No");
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int tcase = 1;
    cin >> tcase;
    while (tcase--) solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 30ms
memory: 7108kb

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