Submission #60075549


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793238462643383279502884L
#define LL long long
#define DD double
#define ULL unsigned long long
#define STR string
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
#define MLL map<LL, LL>
#define MSL map<STR, LL>
#define MLB map<LL, bool>
template <class T>
using PQA = priority_queue<T, V<T>, greater<T>>;
template <class T>
using PQD = priority_queue<T, V<T>, less<T>>;
#define IT iterator
#define F first
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>

using namespace std;
#define PI 3.141592653589793238462643383279502884L
#define LL long long
#define DD double
#define ULL unsigned long long
#define STR string
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
#define MLL map<LL, LL>
#define MSL map<STR, LL>
#define MLB map<LL, bool>
template <class T>
using PQA = priority_queue<T, V<T>, greater<T>>;
template <class T>
using PQD = priority_queue<T, V<T>, less<T>>;
#define IT iterator
#define F first
#define S second
#define PB push_back
#define PLL pair<LL, LL>
#define MP make_pair
#define rep(i, e) for (LL i = 0; i < e; i++)
#define repa(i, s, e) for (LL i = s; i < e; i++)
#define repd(i, s, e) for (LL i = s; i >= e; i--)
#define repauto(x, s) for (auto x : s)
#define rd(...) \
  __VA_ARGS__;  \
  read(__VA_ARGS__)
#define rdv(value, ...) \
  value(__VA_ARGS__);   \
  cin >> value
template <class T>
auto &operator>>(istream &is, vector<T> &xs)
{
  for (auto &x : xs)
    is >> x;
  return is;
}
template <class T>
auto &operator<<(ostream &os, vector<T> &xs)
{
  int sz = xs.size();
  rep(i, sz) os << xs[i] << " \n"[i + 1 == sz];
  return os;
}
template <class T, class Y>
auto &operator<<(ostream &os, pair<T, Y> &xs)
{
  os << "{" << xs.first << ", " << xs.second << "}";
  return os;
}
template <class T, class Y>
auto &operator>>(istream &is, vector<pair<T, Y>> &xs)
{
  for (auto &[x1, x2] : xs)
    is >> x1 >> x2;
  return is;
}
template <class... Args>
auto &read(Args &...args) { return (cin >> ... >> args); }
#define vsorta(v) sort(v.begin(), v.end())
#define vsortd(v) sort(v.begin(), v.end(), greater<>())
#define sort_arr(v, n) sort(v, v + n)
#define rev(v) reverse(v.begin(), v.end())
#define pr(x) cout << x
#define prs(x) cout << x << ' '
#define prn(x) cout << x << '\n'
#define prd() cout << fixed << setprecision(50);
#define Yes cout << "Yes\n"
#define YES cout << "YES\n"
#define No cout << "No\n"
#define NO cout << "NO\n"
#define PN cout << '\n'
#define PS cout << ' '
#define INF (1LL << 60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N 100100

V<PLL> run_length_encoding(V<LL> s)
{
  LL n = (LL)s.size();
  V<PLL> rle;
  LL pre = s[0];
  LL count = 1;
  repa(i, 1, n)
  {
    if (pre != s[i])
    {
      rle.PB({pre, count});
      pre = s[i];
      count = 1;
    }
    else
      count++;
  }
  rle.PB(MP(pre, count));

  V<PLL> x;
  repauto(y, rle)
  {
    if (y.second > 2)
    {
      x.push_back({y.first, 2});
      x.push_back({y.first, 2});
    }
    else
    {
      x.push_back(y);
    }
  }
  return x;
}

void solve()
{
  LL rd(n);
  V<LL> rdv(s, n);
  auto a = run_length_encoding(s);
  V<bool> x(2 * n, 0);
  LL ans = 0, m = a.size(), j = 0, cur = 0;
  rep(i, m)
  {
    j = max(i, j);

    while (j < m && a[j].second == 2 && x[a[j].first] == false)
    {
      x[a[j].first] = true;
      cur++;
      j++;
    }

    ans = max(cur * 2, ans);
    if (x[a[i].first] == true)
    {
      cur--;
      x[a[i].first] = false;
    }
  }
  ans = max(cur * 2, ans);
  prn(ans);
}

int main()
{
  LL T = 1;
  // LL rd(T);
  while (T--)
    solve();
  return 0;
}

Submission Info

Submission Time
Task D - 1122 Substring
User togi11
Language C++ 20 (gcc 12.2)
Score 425
Code Size 3293 Byte
Status AC
Exec Time 40 ms
Memory 15464 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 3
AC × 39
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3460 KB
example_01.txt AC 1 ms 3448 KB
example_02.txt AC 1 ms 3464 KB
hand_00.txt AC 37 ms 10952 KB
hand_01.txt AC 39 ms 15336 KB
hand_02.txt AC 37 ms 10924 KB
hand_03.txt AC 37 ms 10972 KB
hand_04.txt AC 32 ms 6332 KB
hand_05.txt AC 1 ms 3496 KB
random_00.txt AC 39 ms 10648 KB
random_01.txt AC 38 ms 10688 KB
random_02.txt AC 40 ms 10648 KB
random_03.txt AC 38 ms 11008 KB
random_04.txt AC 37 ms 10952 KB
random_05.txt AC 37 ms 11112 KB
random_06.txt AC 37 ms 10972 KB
random_07.txt AC 37 ms 10916 KB
random_08.txt AC 37 ms 10948 KB
random_09.txt AC 38 ms 10956 KB
random_10.txt AC 36 ms 10676 KB
random_11.txt AC 39 ms 10648 KB
random_12.txt AC 37 ms 10752 KB
random_13.txt AC 37 ms 10888 KB
random_14.txt AC 37 ms 10888 KB
random_15.txt AC 37 ms 10952 KB
random_16.txt AC 37 ms 10908 KB
random_17.txt AC 37 ms 10908 KB
random_18.txt AC 37 ms 10996 KB
random_19.txt AC 36 ms 10964 KB
random_20.txt AC 39 ms 14544 KB
random_21.txt AC 37 ms 10904 KB
random_22.txt AC 38 ms 11176 KB
random_23.txt AC 37 ms 10952 KB
random_24.txt AC 36 ms 10892 KB
random_25.txt AC 37 ms 10904 KB
random_26.txt AC 39 ms 14508 KB
random_27.txt AC 37 ms 11144 KB
random_28.txt AC 39 ms 15404 KB
random_29.txt AC 39 ms 15464 KB


2025-03-05 (Wed)
20:46:25 +00:00