QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#141995#6851. Cyclically IsomorphicsupepapupuTL 0ms0kbC++171.4kb2023-08-18 09:54:262023-08-18 09:54:29

Judging History

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

  • [2023-08-18 09:54:29]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-08-18 09:54:26]
  • 提交

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() {
    int tcase = 1;
    cin >> tcase;
    while (tcase--) solve();
}

详细

Test #1:

score: 0
Time Limit Exceeded

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: