QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#431357#6851. Cyclically IsomorphicCidoaiML 0ms0kbC++141.0kb2024-06-05 13:39:332024-06-05 13:39:33

Judging History

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

  • [2024-06-05 13:39:33]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2024-06-05 13:39:33]
  • 提交

answer

#include<cstdio>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
inline ll read(){
	ll x=0;
	int f=0,ch=0;
	while(ch<48||ch>57) f=(ch=='-'),ch=getchar();
	while(ch>47&&ch<58) x=(x<<3)+(x<<1)+(ch&15),ch=getchar();
	return f?-x:x;
}
inline void write(ll x,char end=' '){
	if(x==0){
		putchar('0');
		putchar(end);
		return;
	}
	if(x<0) putchar('-'),x=-x;
	int ch[40]={0},cnt=0;
	while(x){
		ch[cnt++]=(int)(x%10);
		x/=10;
	}
	while(cnt--) putchar(ch[cnt]+48);
	putchar(end);
}
const int N=1e5+5;
int n,m;
string s;
int fa[N];
map<string,int> mp;
int main(){
	int T=read();
	while(T--){
		n=read(),m=read();
		mp.clear();
		for(int i=1;i<=n;++i) fa[i]=i;
		for(int i=1;i<=n;++i){
			cin>>s;
			if(mp[s])
				fa[i]=fa[mp[s]];
			else{
				for(int j=1;j<=m;++j){
					char c=s[0];
					s.erase(s.begin());
					s.push_back(c);
					mp[s]=i;
				}
			}
		}
		int q=read();
		while(q--){
			int x=read(),y=read();
			if(fa[x]==fa[y]) puts("Yes");
			else puts("No");
		}
	}
	return 0;
}

详细

Test #1:

score: 0
Memory 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: