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 <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
using vi = vector<int>;
using ll = long long;
#define sz(x) int(x.size())
int n, k;
vi a(51);
vi getv(int l, int d)
{
vi res;
for(int i = l; i < l+d; i++) res.push_back(a[i]);
return res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++)
{
for(int l = 1; i + k*l - 1 <= n; l++)
{
// cerr << i << ' ' << l << '\n';
vi A = getv(i, l);
bool works = 1;
for(int q = 1; q <= k-1; q++)
{
if(getv(i+q*l, l) != A)
{
works = 0;
break;
}
}
if(works)
{
cout << sz(A) << '\n';
for(int a:A) cout << a << ' ';
cout << '\n';
return 0;
}
}
}
cout << -1 << '\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... |