codeforces222A

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

codeforces222A
#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

 

上一篇:PHP中private、public、protected的区别详解


下一篇:MyBatis中的resultType和resultMap