Advertisement
Guest User

różnica xd :p

a guest
Apr 24th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.10 KB | None | 0 0
  1. #include <bits/stdc++.h> // Tomasz Nowak
  2. using namespace std;
  3.  
  4. #define FOR(i,a,n) for (auto i = (a), i##__ = (n); i <= i##__; ++i)
  5. #define REP(i,n) FOR(i,0,(n)-1)
  6. #define FORD(i,a,n) for (auto i = (a), i##__ = (n); i >= i##__; --i)
  7. #define REPD(i,n) FORD(i,(n)-1,0)
  8. #define ALL(x) x.begin(), x.end()
  9. #define EB emplace_back
  10. #define ST first
  11. #define ND second
  12. #define SZ(x) ((int)x.size())
  13. #define RS resize
  14. #define V vector
  15. constexpr char nl = '\n';
  16. template<class T, class B> void mini(T &&a, B &&b) { if (b < a) a = b; }
  17. template<class T, class B> void maxi(T &&a, B &&b) { if (b > a) a = b; }
  18. int pow2(int x) { return x < 2 ? 0 : sizeof(x) * 8 - __builtin_clz(x - 1); }
  19.  
  20. #define _S(zn, a...) typename enable_if<is_same<a, typename remove_reference<T>::type>::value zn 1, int>::type()
  21. #define _F(func, a...) template<class T> auto func(T &&x) -> decltype(a)
  22. template<class T> struct Off { T __a, __b; };
  23. _F(O, _S(!=, string), Off<decltype(x.begin())>()) { return { ALL(x) }; }
  24. _F(O, cerr << x, x) { return x; }
  25. _F(O, x.first, x) { return x; }
  26. #define _OP(a...) _F(operator<<, a, *this)
  27. #define RTH return *this
  28. struct Debug {
  29.     ~Debug() { cerr << nl; }
  30.     Debug& operator()(int x = 0) { REP(a, x+1) cout << "  "; RTH; }
  31.     _OP(cerr << x) { cerr << O(x); RTH; }
  32.     _OP(x.begin(), _S(!=, string)) {
  33.         cerr <<  "{\n";
  34.         for (auto a = x.begin(); a != x.end(); ++a)
  35.     *this << "  " << distance(x.begin(), a) << ": " << O(*a) << '\n';
  36.         RTH << "}";
  37.     }
  38.     _OP(x.first) { RTH << "(" << O(x.first) << ", " << O(x.second) << ")"; }
  39.     _OP(x.__a) {
  40.         cerr << "{";
  41.         for (auto a = x.__a, b = x.__b; a != b; ++a)
  42.     *this << O(*a) << (next(a) == b ? "" : ", ");
  43.         RTH << "}";
  44.     }
  45. };
  46. struct DebugOff {
  47.     template<class T> DebugOff& operator<<(T&&) { RTH; }
  48.     DebugOff& operator()(int = 0) { RTH; }
  49. };
  50. #ifdef DEBUG
  51. # define D Debug()
  52. # define DD(a...) a
  53. #else
  54. # define D DebugOff()
  55. # define DD(...)
  56. #endif
  57. #define I(a...) #a ": " << a << "   "
  58. #define TD(C, a...) _F(O, _S(==, C), x) { return x; } Debug& operator<<(Debug &d, C &x) { a; return d; }
  59.  
  60. using VI    = V<int>;
  61. using VVI   = V<VI>;
  62. using LL    = long long;
  63. using VLL   = V<LL>;
  64. using PII   = pair<int, int>;
  65. using VPII  = V<PII>;
  66. using VVPII = V<VPII>;
  67. using VB    = V<bool>;
  68.  
  69. // end of templates v7
  70.  
  71. int main()
  72. {
  73.     ios_base::sync_with_stdio(0);
  74.     cin.tie(0);
  75.  
  76.     //WCZYTYWANIE DANYCH
  77.     int n;
  78.     cin >> n;
  79.     VI word(n);
  80.     REP(i, n)
  81.     {
  82.         char a;
  83.         cin >> a;
  84.         word[i] = a - 'a';
  85.     }
  86.     D << I(n) << I(word);
  87.     //robienie rzeczy
  88.     VVI pary;
  89.     VI l_wyst(26);
  90.     REP(i, n)
  91.         ++l_wyst[word[i]];
  92.     REP(i, 26)
  93.         if(l_wyst[i])
  94.             REP(j, 26)
  95.                 if(j != i && l_wyst[j] != 0)
  96.                 {
  97.                     pary.EB(VI (0));
  98.                     REP(k, n)
  99.                         if(word[k] == i || word[k] == j)
  100.                             pary[pary.size() - 1].EB(word[k]);
  101.                 }
  102.     D << I(pary);
  103.     int answ = 0;
  104.     if(pary.empty())
  105.     {
  106.         cout << 0;
  107.         return 0;
  108.     }
  109.     else
  110.     {
  111.         REP(i, SZ(pary))
  112.         {
  113.             int www = 0;
  114.             int p = pary[i][0];
  115.             REP(j, n)
  116.             {
  117.                 if(pary[i][j] == p)
  118.                     pary[i][j] = 1;
  119.                 else
  120.                     pary[i][j] = -1;
  121.             }
  122.             int wynik = 0, suma = 0, suma_pop = 0, mini = 1e9;
  123.             REP(j, n)
  124.             {
  125.                 suma += pary[i][j];
  126.                 if(pary[i][j] == -1)
  127.                 {
  128.                     mini = min(mini, suma_pop);
  129.                     suma_pop = suma;
  130.                 }
  131.                 wynik = max(wynik, suma - mini);
  132.             }
  133.             REP(j, n)
  134.                 pary[i][j] *= -1;
  135.             int wynik2 = 0, suma2 = 0, suma_pop2 = 0, mini2 = 1e9;
  136.             REP(j, n)
  137.             {
  138.                 suma2 += pary[i][j];
  139.                 if(pary[i][j] == -1)
  140.                 {
  141.                     mini2 = min(mini2, suma_pop2);
  142.                     suma_pop2 = suma2;
  143.                 }
  144.                 wynik2 = max(wynik2, suma2 - mini2);
  145.             }      
  146.             www = max(wynik, wynik2);
  147.             answ = max(answ, www); 
  148.         }
  149.     }
  150.  
  151.     cout << answ;
  152.  
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement