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;
int main() {
int n, k;
cin >> n >> k;
vector<int> nums(n);
for (int i = 0; i < n; i++) {
cin >> nums[i];
}
int ans_len = -1, ans_start = -1;
bool found = false;
for (int i = 0; i < n && !found; i++) {
for (int j = i; j < n && !found; j++) {
int len = j-i+1;
bool valid = true;
for (int l = 1; l < k && valid; l++) {
for (int m = 0; m < len && valid; m++) {
int idx = i + l*len + m;
if (idx < n) {
if (nums[i+m] != nums[idx]) {
valid = false;
break;
}
}
else {
valid = false;
break;
}
}
}
if (valid) {
ans_len = len;
ans_start = i;
found = true;
break;
}
}
}
if (ans_len == -1)
cout << -1 << '\n';
else {
cout << ans_len << '\n';
for (int i = ans_start; i < ans_start+ans_len; i++)
cout << nums[i] << ' ';
cout << '\n';
}
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... |