이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* author: NotLinux
* created: 07.09.2022 ~ 15:01:43
**/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#ifdef LOCAL
#include "/home/notlinux/debug.h"
#else
#define debug(x...) void(37)
#endif
vector < int > arr;
bool Is_same(int l , int r){
vector < int > v1,v2;
for(int i = l;i<=(l+r)/2;i++){
v1.push_back(arr[i]);
}
for(int i = (l+r)/2+1;i<=r;i++){
v2.push_back(arr[i]);
}
return (v1 == v2);
}
void solve(){
int n ,k ;cin >> n >> k;
arr.resize(n);
for(auto &inp : arr)cin >> inp;
vector < int > ans;
int lol = 0;
for(int len = 1;len*k <= n ;len++){
vector < int > dp(n,1LL);
for(int j = len-1;j<n;j++)dp[j] = 1;
for(int j = 2*len-1;j<n;j++){
dp[j] += dp[j-2*len+1] * Is_same(j-2*len+1,j);
}
int mpos = *max_element(dp.begin()+len,dp.end());
int mindpos = max_element(dp.begin()+len,dp.end()) - dp.begin();
vector < int > locarr;
for(int j = mindpos-len+1;j<=mindpos;j++)locarr.push_back(arr[j]);
if(lol < mpos){
ans = locarr;
lol = mpos;
}
}
if(lol < k){
cout << "-1" << endl;
return;
}
cout << (int)ans.size() << endl;
for(auto itr : ans)cout << itr << " ";
cout << endl;
}
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(nullptr);
int tt=1;
// cin >> tt;
while(tt--)solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |