제출 #982579

#제출 시각아이디문제언어결과실행 시간메모리
982579Ghetto서열 (APIO23_sequence)C++17
7 / 100
87 ms33580 KiB
#include "sequence.h" #include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; const int MAX_N = 5e5 + 5; int n; int a[MAX_N]; vector<pii> ranges[MAX_N]; void precomp() { int i = 1; while (i != n + 1) { int j = i; while (j < n && a[j + 1] == a[i]) j++; ranges[a[i]].push_back({i, j}); i = j + 1; } } int sequence(int tmp_n, vector<int> tmp_a) { n = tmp_n; for (int i = 0; i < n; i++) a[i + 1] = tmp_a[i]; precomp(); int ans = 0; for (int i = 1; i <= n; i++) { if (ranges[i].empty()) continue; for (pii x : ranges[i]) ans = max(ans, x.second - x.first + 1); if (ranges[i].size() == 1) continue; assert(ranges[i].size() == 2); int range_size = 0; for (pii x : ranges[i]) range_size += x.second - x.first + 1; int in_size = ranges[i][1].first - ranges[i][0].second + 1; int out_size = ranges[i][0].first - 1 + n - ranges[i][1].second; if (out_size >= in_size - range_size) ans = max(ans, range_size); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...