Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using Tvi=vector<int>;
- using Tvvi=vector<Tvi>;
- using Tbs=bitset<1001>;
- using Tvbs=vector<Tbs>;
- int n,m,x,NrMaxM,NrMaxC,nre;
- Tvi v;
- Tvvi A;
- Tvbs c1,c2;
- unordered_map<int,int> mp;
- #define DIM 1280000
- char buff[DIM];
- int poz=0;
- void citeste(int &numar) /// Parsarea numerelor naturale
- {
- numar=0;
- while(buff[poz]<'0'||buff[poz]>'9') /// Cat timp caracterul din buffer nu e cifra ignor
- if(++poz==DIM) ///daca am "golit" bufferul atunci il umplu
- fread(buff,1,DIM,stdin),poz=0;
- while('0'<=buff[poz]&&buff[poz]<='9') /// Cat timp dau de o cifra recalculez numarul
- {
- numar=numar*10+buff[poz]-'0';
- if(++poz==DIM)
- fread(buff,1,DIM,stdin),poz=0;
- }
- }
- int main()
- {
- citeste(n),citeste(m);
- A=Tvvi(n+1,Tvi(m));
- for(int i=1;i<=n;++i)
- for(int& x:A[i])
- citeste(x),v.emplace_back(x);
- sort(v.begin(),v.end());
- v.erase(unique(v.begin(),v.end()),v.end()); /// Eliminare si stergere duplicate
- for(const int& x:v)
- mp[x]=++nre;
- c1=Tvbs(nre+1);
- c2=Tvbs(n+1);
- for(int i=1;i<=n;++i)
- for(int& x:A[i])
- x=mp[x],c1[x].set(i),c2[i].set(x);
- for(int i=1;i<=nre;++i)
- NrMaxM=max(NrMaxM,static_cast<int>(c1[i].count()));
- for(int i=1;i<n;++i)
- for(int j=i+1;j<=n;++j)
- NrMaxC=max(NrMaxC,static_cast<int>((c2[i]&c2[j]).count()));
- cout<<NrMaxM<<'\n'<<NrMaxC;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement