QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#140953 | #6851. Cyclically Isomorphic | neko_nyaa | AC ✓ | 95ms | 4484kb | C++23 | 1.0kb | 2023-08-17 01:07:25 | 2023-08-17 01:07:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int minRotation(string s) {
int a=0, N=sz(s); s += s;
rep(b,0,N) rep(k,0,N) {
if (a+k == b || s[a+k] < s[b+k]) {b += max(0, k-1); break;}
if (s[a+k] > s[b+k]) { a = b; break; }
}
return a;
}
void solve() {
int n, m; cin >> n >> m;
map<string, int> ss;
map<int, int> pr;
for (int i = 1; i <= n; i++) {
string s; cin >> s;
int k = minRotation(s);
rotate(s.begin(), s.begin()+k, s.end());
if (ss[s] == 0) {
ss[s] = i;
pr[i] = i;
} else {
pr[i] = ss[s];
}
}
int q; cin >> q;
while (q--) {
int x, y; cin >> x >> y;
if (pr[x] == pr[y]) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int t; cin >> t;
while (t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 95ms
memory: 4484kb
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