Tranvick

Untitled

Apr 5th, 2012
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 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 d[1001][1001],n,m,a[N],b[1001];
  46.  
  47. inline bool check(int k){
  48.     int ans=0;
  49.     forn(i,1000) for (int j=i+1;j<=1000;j++) if (b[i] && b[j] && d[i][j]>=k) ++ans;
  50.     return ans<=m;
  51. }
  52.  
  53. int main(){
  54.     scanf("%d%d",&n,&m);
  55.     mem(d,63);
  56.     forn(i,n){
  57.         scanf("%d",&a[i]);
  58.         b[a[i]]=1;
  59.     }
  60.     forn(i,n) forn(j,i-1){
  61.         int l=a[i],r=a[j];
  62.         if (l>r) swap(l,r);
  63.         d[l][r]=min(d[l][r],i-j-1);
  64.     }
  65.     forn(k,n-2){
  66.         if (check(k)){
  67.             printf("%d\n",k);
  68.             return 0;
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment