This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
void testCase() {
int n, k;
cin >> n >> k;
vector<int> a(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= n; ++i) {
for (int j = i; j <= n; ++j) {
if ((j - i + 1) % k == 0) {
vector<int> pattern, v;
bool ok = true;
for (int p = i; p <= j && ok; ++p) {
v.emplace_back(a[p]);
if ((int)v.size() == (j - i + 1) / k) {
if (pattern.empty()) {
pattern = v;
} else {
if (v != pattern) {
ok = false;
}
}
v.clear();
}
}
if (ok) {
cout << pattern.size() << '\n';
for (int x : pattern) {
cout << x << ' ';
}
cout << '\n';
return;
}
}
}
}
cout << "-1\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tests = 1;
for (int tc = 0; tc < tests; ++tc) {
testCase();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |