CodeForces - 1090M

题意:

给一个n,有k种颜色

接着有n个数,每个数代表一个颜色。问你最长相邻颜色不同的区间长度是多长

复杂度 On

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string.h>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
const int maxn =1e5+5;
const int maxm=10000;
const int mod =1e9+7;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
int a[maxn];
int main()
{
    int n,k;scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    int ans=1;int cnt=1;
    for(int i=1;i<n;i++)
    {
        if(a[i]!=a[i-1]) cnt++;
        else cnt=1;
        ans=max(ans,cnt);
    }
    printf("%d\n",ans);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/wzazzy/article/details/85053640
今日推荐