a53

John_cu_bitset

a53
Dec 29th, 2020 (edited)
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. namespace FastRead {
  3. const int Dim(1e5);
  4. char buff[Dim];
  5. int pos, len;
  6. inline char nc() {
  7. if (pos == len) {
  8. pos = 0;
  9. len = fread(buff, 1, Dim, stdin);
  10. if (!len) return EOF;
  11. }
  12. return buff[pos++];
  13. }
  14. template<class T> inline void Read(T& x) {
  15. char ch;
  16. int sgn(1);
  17. while (!isdigit(ch = nc()))
  18. if (ch == '-')
  19. sgn = -1;
  20. x = ch - '0';
  21. while (isdigit(ch = nc()))
  22. x = x * 10 + (ch - '0');
  23. x *= sgn;
  24. }
  25. }
  26. using namespace FastRead;
  27. using namespace std;
  28. using VI = vector<int>;
  29. using VVI = vector<VI>;
  30. using BITSET = bitset<1001>;
  31. using VB = vector<BITSET>;
  32. int n, m, x, mmax, cmax, curr;
  33. VI v;
  34. VVI retin;
  35. VB f1, f2;
  36. unordered_map<int, int> mp;
  37. int main() {
  38. Read(n), Read(m);
  39. retin = VVI(n + 1, VI(m));
  40. for (int i = 1; i <= n; ++i)
  41. for (int& x : retin[i]) {
  42. Read(x);
  43. v.emplace_back(x);
  44. }
  45. sort(v.begin(), v.end());
  46. v.erase(unique(v.begin(), v.end()), v.end());
  47. for (const int& x : v)
  48. mp[x] = ++curr;
  49. f1 = VB(curr + 1);
  50. f2 = VB(n + 1);
  51. for (int i = 1; i <= n; ++i)
  52. for (int& x : retin[i]) {
  53. x = mp[x];
  54. f1[x].set(i);
  55. f2[i].set(x);
  56. }
  57. for (int i = 1; i <= curr; ++i)
  58. mmax = max(mmax, static_cast<int>(f1[i].count()));
  59. for (int i = 1; i < n; ++i)
  60. for (int j = i + 1; j <= n; ++j)
  61. cmax = max(cmax, static_cast<int>((f2[i] & f2[j]).count()));
  62. cout << mmax << '\n' << cmax;
  63. exit(0);
  64. }
Advertisement
Add Comment
Please, Sign In to add comment