QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#140953#6851. Cyclically Isomorphicneko_nyaaAC ✓95ms4484kbC++231.0kb2023-08-17 01:07:252023-08-17 01:07:27

Judging History

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

  • [2023-08-17 01:07:27]
  • 评测
  • 测评结果:AC
  • 用时:95ms
  • 内存:4484kb
  • [2023-08-17 01:07:25]
  • 提交

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