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;
const int N = 50 + 5;
int n, k, arr[N];
bool check(int l, int l2, int cnt){
for(int i = 0; i < cnt; i++) if(arr[l + i] != arr[l2 + i]) return false;
return true;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> arr[i];
for(int len = 1; len <= n; len++){
for(int i = 1; i <= n; i++){
int cnt = 0;
for(int j = i; j <= n; j += len){
if(j + len - 1 > n) break;
else{
if(check(i, j, len)) cnt++;
else break;
}
}
if(cnt >= k){
cout << len << "\n";
for(int j = i; j < i + len; j++) cout << arr[j] << " ";
return 0;
}
}
}
cout << -1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |