QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#141995 | #6851. Cyclically Isomorphic | supepapupu | TL | 0ms | 0kb | C++17 | 1.4kb | 2023-08-18 09:54:26 | 2023-08-18 09:54:29 |
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...