Tranvick

Untitled

Apr 4th, 2012
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. #pragma comment(linker, "/STACK:65777216")
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cstdlib>
  5. #include <ctime>
  6. #include <cstdio>
  7. #include <algorithm>
  8. #include <cmath>
  9. #include <vector>
  10. #include <set>
  11. #include <stack>
  12. #include <map>
  13. #include <queue>
  14. #include <string>
  15. #include <memory.h>
  16. #include <iterator>
  17. #define y1 trololoy1
  18. #define y0 trololoy0
  19. #define mem(A,X) memset(A,X,sizeof(A))
  20. #define memo(A) memset(A,0,sizeof(A))
  21. #define forn(I,B) for (int I=1;I<=(B);I++)
  22. #define forg(H,V) for (int H=first[V];h;h=next[H])
  23. #define rep(I,B) for (int I=0;I<(B);I++)
  24. #define labs(X) (((X)>0)?(X):(-(X)))
  25. #define ropen(X) freopen(X,"r",stdin)
  26. #define wopen(X) freopen(X,"w",stdout)
  27. #define rwopen(X) freopen(X".in","r",stdin);freopen(X".out","w",stdout)
  28. #define pb push_back
  29. #define mp make_pair
  30. #define all(X) (X).begin(),(X).end()
  31. #define sqr(X) ((X)*(X))
  32.  
  33. using namespace std;
  34.  
  35. typedef pair <int,int> pii;
  36. typedef double ld;
  37. typedef long long ll;
  38. typedef pair <ll,ll> pll;
  39. typedef vector<int> vi;
  40. const int N=111111;
  41. const int INF=111111111;
  42. const double eps=1e-9;
  43. const double pi=3.14159265358979;
  44.  
  45. int n,m,a[N],c[1001];
  46. pii t[N];
  47.  
  48. inline bool check(int k){
  49.     int l=1,r=k+1;
  50.     memo(c);
  51.     int kv=0,ans=0;
  52.     forn(i,k+1) ++c[a[i]];
  53.     while (r<=n){
  54.         if (a[l]!=a[r] && c[a[l]]==1 && c[a[r]]==1) t[++kv]=pii(min(a[l],a[r]),max(a[l],a[r]));
  55.         --c[a[l]];
  56.         ++c[a[r+1]];
  57.         ++l;++r;
  58.     }
  59.     sort(t+1,t+kv+1);
  60.     forn(i,kv) if (t[i]!=t[i-1]) ++ans;
  61.     return ans<=m;
  62. }
  63.  
  64. int main(){
  65.     scanf("%d%d",&n,&m);    
  66.     forn(i,n) scanf("%d",&a[i]);
  67.     int l=1,r=n-2;
  68.     while (l<r){
  69.         int m=(l+r)/2;
  70.         if (check(m)) r=m;
  71.         else l=m+1;
  72.     }
  73.     if (r!=1 && check(r-1)) printf("%d\n",r-1);
  74.     else printf("%d\n",r);
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment