时间限制是3S
数据:https://www.udebug.com/UVa/12174
求大神解答
代码
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int t,n,s,pd,ans,a[100010],book[100010];
int main()
{
freopen("uva12174.in","r",stdin);
freopen("uva12174.out","w",stdout);
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&s,&n);
memset(a,0,sizeof a);
memset(book,0,sizeof book);
pd=0;ans=0;
for(int i=1;i<=n;i++) scanf("%d",a+i);
for(int j=1;j<=s;j++)
{
pd=0;
memset(book,0,sizeof book);
for(int i=1;i<=n;i++)
{
if(i==j+1||pd>=s) {memset(book,0,sizeof book); pd=0;}
if(i<=j)
{
if(book[a[i]]) break;
else if(a[i]) book[a[i]]=1;
pd++;
}
else
{
if(book[a[i]]) break;
else if(a[i]) book[a[i]]=1;
pd++;
}
if(i==n)ans++;
}
}
printf("%d\n",ans);
}
return 0;
}