Submission #60077243
Source Code Expand
#pragma region headers
#include <algorithm>
#include <bit>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
// #include <queue>
#include <set>
#include <string>
// #include <unordered_map>
// #include <unordered_set>
#include <vector>
// #include <sstream>
#include <cmath>
#include <functional>
#include <numbers>
#include <numeric>
// #include <bit>
// #include <boost/multiprecision/cpp_dec_float.hpp>
#pragma endregion
#pragma region pre
#ifndef _MSC_VER
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
using namespace std;
using namespace std::literals;
// #include <atcoder/all>
// using namespace atcoder;
using ll = long long;
using pll = pair<ll, ll>;
using str = std::string;
template<typename T>
using vec = std::vector<T>;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define reps(i, n, s) for (int i = static_cast<int>(s); i < static_cast<int>(n); i++)
#define all(x) std::begin(x), std::end(x)
template<typename T>
inline bool chmax(T& a, T b) {
return ((a < b) ? (a = b, true) : (false));
}
template<typename T>
inline bool chmin(T& a, T b) {
return ((a > b) ? (a = b, true) : (false));
}
int constexpr intmax = numeric_limits<int>().max();
int constexpr intmin = numeric_limits<int>().min();
ll constexpr llmax = numeric_limits<ll>().max();
ll constexpr llmin = numeric_limits<ll>().min();
// std::ostream& operator<<(std::ostream& os, const atcoder::modint1000000007& obj) {
// return os << obj.val();
// }
//
// std::ostream& operator<<(std::ostream& os, const atcoder::modint998244353& obj) {
// return os << obj.val();
// }
template<typename T, typename U>
std::ostream& operator<<(std::ostream& os, const pair<T, U>& obj) {
return os << "(" << obj.first << ", " << obj.second << ")";
}
template<typename... Args>
void print(Args... args) {
auto t = tie(args...);
apply([](auto&&... args) { ((cout << args << ' '), ...); }, t);
cout << '\n';
}
template<typename... Args>
void prints(Args... args) {
auto t = tie(args...);
apply([](auto&&... args) { ((cout << args << ' '), ...); }, t);
cout << ' ';
}
template<typename T>
void printv(const T& container, int width = 3) {
for (auto it = container.begin(); it != container.end(); ++it) {
cout << setw(width - 1) << *it << " ";
}
cout << endl;
}
template<typename T>
void printv2(const T& container, int width = 3) {
for (auto it = container.begin(); it != container.end(); ++it) {
for (auto it2 = it->begin(); it2 != it->end(); ++it2) {
cout << setw(width - 1) << *it2 << " ";
}
cout << endl;
}
}
template<typename T>
void printv3(const T& container, int width = 3) {
for (auto it = container.begin(); it != container.end(); ++it) {
for (auto it2 = it->begin(); it2 != it->end(); ++it2) {
for (auto it3 = it->begin(); it3 != it->end(); ++it3) {
cout << setw(width - 1) << *it3 << " ";
}
cout << endl;
}
cout << endl
<< endl;
}
}
template<typename T>
std::vector<T> create_vec(const T& value, size_t size) {
return std::vector<T>(size, value);
}
template<typename T, typename... Dims>
auto create_vec(const T& value, size_t first, Dims... dims) {
return std::vector<decltype(create_vec<T>(value, dims...))>(first, create_vec(value, dims...));
}
void yesno(bool cond) {
cout << (cond ? "Yes" : "No") << endl;
}
void init_io() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
cout << std::setprecision(24);
}
#pragma endregion
#include <random>
std::random_device seed_gen;
std::mt19937 engine(seed_gen());
ll getRandom(ll min, ll max) { // [min ... max]
std::uniform_int_distribution<ll> dist(min, max);
return dist(engine);
}
using P = tuple<ll, ll, ll>;
std::ostream& operator<<(std::ostream& os, const P& obj) {
return os << "(" << get<0>(obj) << "," << get<1>(obj) << "," << get<2>(obj) << ")";
}
class Solution {
public:
// using mint = atcoder::modint998244353;
// using mint = atcoder::modint1000000007;
void run() {
ll n;
cin >> n;
vec<int> a(n);
rep(i, n) {
cin >> a[i];
}
vec<pair<int, int>> rle;
int cnt = 0;
rep(i, n) {
if (i == n - 1 || a[i + 1] != a[i]) {
rle.emplace_back(a[i], cnt + 1);
cnt = 0;
}
else {
++cnt;
}
}
// printv(rle);
int ans = 0;
int l = -1;
set<int> nums;
rep(i, rle.size()) {
auto [num, cnt] = rle[i];
if (l == -1) {
if (cnt >= 2) {
l = i;
nums.insert(num);
chmax(ans, (int)nums.size() * 2);
// print(l, i);
}
}
else {
if (cnt >= 2) {
if (nums.contains(num)) {
for (; l < i; ++l) {
auto [ns, nc] = rle[l];
nums.erase(ns);
if (ns == num) {
break;
}
}
++l;
}
nums.insert(num);
chmax(ans, (int)nums.size() * 2);
// print(l, i);
if (cnt > 2) {
l = i;
nums.clear();
nums.insert(num);
}
}
else {
l = -1;
nums.clear();
}
}
}
print(ans);
}
};
int main() {
init_io();
Solution().run();
return 0;
}
Submission Info
| Submission Time |
|
| Task |
D - 1122 Substring |
| User |
skrstyle |
| Language |
C++ 20 (gcc 12.2) |
| Score |
425 |
| Code Size |
5286 Byte |
| Status |
AC |
| Exec Time |
61 ms |
| Memory |
9404 KiB |
Compile Error
Main.cpp:1: warning: ignoring ‘#pragma region headers’ [-Wunknown-pragmas]
1 | #pragma region headers
|
Main.cpp:24: warning: ignoring ‘#pragma endregion ’ [-Wunknown-pragmas]
24 | #pragma endregion
|
Main.cpp:26: warning: ignoring ‘#pragma region pre’ [-Wunknown-pragmas]
26 | #pragma region pre
|
Main.cpp:147: warning: ignoring ‘#pragma endregion ’ [-Wunknown-pragmas]
147 | #pragma endregion
|
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
425 / 425 |
| Status |
|
|
| 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 |
3400 KiB |
| example_01.txt |
AC |
1 ms |
3480 KiB |
| example_02.txt |
AC |
1 ms |
3488 KiB |
| hand_00.txt |
AC |
46 ms |
9400 KiB |
| hand_01.txt |
AC |
12 ms |
6008 KiB |
| hand_02.txt |
AC |
44 ms |
9404 KiB |
| hand_03.txt |
AC |
37 ms |
7040 KiB |
| hand_04.txt |
AC |
9 ms |
3872 KiB |
| hand_05.txt |
AC |
1 ms |
3336 KiB |
| random_00.txt |
AC |
15 ms |
4928 KiB |
| random_01.txt |
AC |
16 ms |
4952 KiB |
| random_02.txt |
AC |
18 ms |
4900 KiB |
| random_03.txt |
AC |
22 ms |
4844 KiB |
| random_04.txt |
AC |
25 ms |
4932 KiB |
| random_05.txt |
AC |
25 ms |
4912 KiB |
| random_06.txt |
AC |
29 ms |
4948 KiB |
| random_07.txt |
AC |
20 ms |
4908 KiB |
| random_08.txt |
AC |
19 ms |
4800 KiB |
| random_09.txt |
AC |
15 ms |
5000 KiB |
| random_10.txt |
AC |
14 ms |
4948 KiB |
| random_11.txt |
AC |
17 ms |
4908 KiB |
| random_12.txt |
AC |
18 ms |
4896 KiB |
| random_13.txt |
AC |
21 ms |
4908 KiB |
| random_14.txt |
AC |
25 ms |
4920 KiB |
| random_15.txt |
AC |
25 ms |
4856 KiB |
| random_16.txt |
AC |
28 ms |
4768 KiB |
| random_17.txt |
AC |
28 ms |
4996 KiB |
| random_18.txt |
AC |
31 ms |
4840 KiB |
| random_19.txt |
AC |
31 ms |
4840 KiB |
| random_20.txt |
AC |
28 ms |
7816 KiB |
| random_21.txt |
AC |
41 ms |
9320 KiB |
| random_22.txt |
AC |
36 ms |
8584 KiB |
| random_23.txt |
AC |
50 ms |
8108 KiB |
| random_24.txt |
AC |
61 ms |
9324 KiB |
| random_25.txt |
AC |
58 ms |
8792 KiB |
| random_26.txt |
AC |
27 ms |
6500 KiB |
| random_27.txt |
AC |
31 ms |
6732 KiB |
| random_28.txt |
AC |
12 ms |
5812 KiB |
| random_29.txt |
AC |
12 ms |
5972 KiB |