Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define INF (int)10e6
- #define eps 10e-6
- #define mp make_pair
- #define pb push_back
- #define all(t) t.begin(),t.end()
- #define LL long long
- #define MOD 1000000007
- using namespace std;
- //ifstream fin ("input.txt");
- //ofstream fout ("output.txt");
- LL n,m,ans;
- vector<LL> a[2000];
- LL Intersect(int i,int j){ // пересекает два массива за О(m)
- int p1=0; int p2=0;
- LL res=0;
- while(p1!=m && p2!=m){
- LL x=a[i][p1]; LL y=a[j][p2];
- if(x>y)
- p2++;
- if(x<y)
- p1++;
- if(x==y)
- p1++,p2++,res++;
- }
- return res;
- }
- int main(){
- std::ios::sync_with_stdio(false);
- //freopen("input.in","r",stdin);
- //freopen("output.out","w",stdout);
- cin >> n >> m;
- for(int i=0;i<n;++i){
- a[i].resize(m);
- for(int j=0;j<m;++j){
- cin >> a[i][j];
- }
- }
- for(int i=0;i<n;++i)
- sort(a[i].begin(),a[i].end()); // Сортируем элементы языков,чтобы потом пересекать их за О(m)
- for(int i=0;i<n;++i)
- for(int j=i+1;j<n;++j)
- ans=max(ans,Intersect(i,j));
- ans++;
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement