其他分享
首页 > 其他分享> > codeforces222A

codeforces222A

作者:互联网

sol:显然只有后面一串相同才行,因为只能删除前面的元素

#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
    ll s=0; bool f=0; char ch=' ';
    while(!isdigit(ch)) {f|=(ch=='-'); ch=getchar();}
    while(isdigit(ch)) {s=(s<<3)+(s<<1)+(ch^48); ch=getchar();}
    return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
    if(x<0) {putchar('-'); x=-x;}
    if(x<10) {putchar(x+'0'); return;}
    write(x/10); putchar((x%10)+'0');
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=100005;
int n,m,a[N];
int main()
{
    int i,wn;
    R(n); R(m);
    for(i=1;i<=n;i++) R(a[i]);
    for(i=n;i>=1;i--)
    {
        if(a[i]!=a[n]) {wn=i+1; break;}
        else wn=i;
    }
    if(wn<=m) Wl(wn-1);
    else puts("-1");
    return 0;
}
View Code

 

标签:ch,int,wn,ll,while,isdigit,codeforces222A
来源: https://www.cnblogs.com/gaojunonly1/p/15436947.html