Advertisement
Guest User

Untitled

a guest
Jan 18th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define INF (int)10e6
  4. #define eps 10e-6
  5. #define mp make_pair
  6. #define pb push_back
  7. #define all(t) t.begin(),t.end()
  8. #define LL long long
  9. #define MOD 1000000007
  10.  
  11.  
  12. using namespace std;
  13.  
  14. //ifstream fin ("input.txt");
  15. //ofstream fout ("output.txt");
  16.  
  17. LL n,m,ans;
  18. vector<LL> a[2000];
  19.  
  20. LL Intersect(int i,int j){     // пересекает два массива за О(m)
  21.  
  22.     int p1=0; int p2=0;
  23.     LL res=0;
  24.     while(p1!=m && p2!=m){
  25.         LL x=a[i][p1]; LL y=a[j][p2];  
  26.         if(x>y)
  27.             p2++;
  28.         if(x<y)
  29.             p1++;
  30.         if(x==y)
  31.             p1++,p2++,res++;       
  32.     }
  33.     return res;
  34. }
  35. int main(){
  36.     std::ios::sync_with_stdio(false);
  37.     //freopen("input.in","r",stdin);
  38.     //freopen("output.out","w",stdout);
  39.  
  40.     cin >> n >> m;
  41.     for(int i=0;i<n;++i){
  42.         a[i].resize(m);
  43.         for(int j=0;j<m;++j){
  44.             cin >> a[i][j];
  45.         }
  46.     }
  47.    
  48.     for(int i=0;i<n;++i)
  49.         sort(a[i].begin(),a[i].end());  // Сортируем элементы языков,чтобы потом пересекать их за О(m)
  50.    
  51.     for(int i=0;i<n;++i)
  52.         for(int j=i+1;j<n;++j)
  53.             ans=max(ans,Intersect(i,j));
  54.  
  55.     ans++;
  56.     cout << ans;
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement