You want to type the string , consisting of lowercase Latin letters, using your favorite text editor Notepad#.
Notepad# supports two kinds of operations:
- append any letter to the end of the string; - copy a continuous substring of an already typed string and paste this substring to the end of the string.
Can you type string in strictly less than operations?
## 输入格式
The first line contains a single integer ( ) — the number of testcases.
The first line of each testcase contains a single integer ( ) — the length of the string .
The second line contains a string , consisting of lowercase Latin letters.
The sum of doesn't exceed over all testcases.
## 输出格式
For each testcase, print "YES" if you can type string in strictly less than operations. Otherwise, print "NO".
In the first testcase, you can start with typing "codef" ( operations), then copy "o" ( operation) from an already typed part, then finish with typing "rces" ( operations). That will be operations, which is not strictly less than . There exist other ways to type "codeforces". However, no matter what you do, you can't do less than operations.
In the second testcase, you can type "labac" ( operations), then copy "aba" ( operation), finishing the string in operations.
//Notepad#
//只需要寻找出字符串中是否存在不重叠的两个相同的子串就可以了,字串长度为2就可以了
//利用map存储#include <bits/stdc++.h>
#define int long long
usingnamespace std;
constint N=1e6+10,mod=1e9+7;
string s;
int n,t,a[N],f[N],res,num,ans,m;
bool vis[N];
signed main()
{
std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>t;
while(t--){
cin>>n>>s;
map<string,int>p;
res=0;
for(int i=0;i<s.size();i++){
string tmp;
tmp+=s[i];
tmp+=s[i+1];
if(p.count(tmp)==1&&p[tmp]!=i-1){
cout<<"YES"<<endl;
goto nexts;
}
if(!p.count(tmp)) p[tmp]=i;
}
cout<<"NO"<<endl;
nexts:;
}
return0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)