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;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
const int mxN = 150001;
const int mxK = 401;
int N, K;
int A[mxN];
map<int,int> dpL[mxN], dpR[mxN];
map<int,int> paL[mxN], paR[mxN];
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> K;
N += K;
FOR(i,1,N){
cin >> A[i];
}
if (N-K == 2) {
cout << A[1] _ A[2] << '\n';
return 0;
}
FOR(i,2,N){
FOR(j,max(1,i-K-1),i-1){
int diff = A[i]-A[j];
int r = dpL[j].count(diff) ? dpL[j][diff]+1 : 2;
if (!dpL[i].count(diff) || dpL[i][diff] < r) {
dpL[i][diff] = r;
paL[i][diff] = j;
}
}
}
RFOR(i,N-1,1){
FOR(j,i+1,min(N,i+K+1)){
int diff = A[j]-A[i];
int r = dpR[j].count(diff) ? dpR[j][diff]+1 : 2;
if (!dpR[i].count(diff) || dpR[i][diff] < r) {
dpR[i][diff] = r;
paR[i][diff] = j;
}
}
}
map<int,int> slide;
FOR(i,1,N){
for (auto& x : dpR[i]) {
if (slide.count(x.first) && min(dpL[slide[x.first]][x.first], x.second)*2 >= N-K) {
//cout << "YES" _ x.first _ slide[x.first] _ i << endl;
int a = slide[x.first], b = i;
vector<int> ans;
while (SZ(ans) < (N-K)/2) ans.push_back(a), a = paL[a][x.first];
reverse(ALL(ans));
while (SZ(ans) < N-K) ans.push_back(b), b = paR[b][x.first];
for (int& x : ans) {
cout << A[x] << ' ';
}
cout << endl;
return 0;
}
}
for (auto& x : dpL[i]) {
if (!slide.count(x.first) || dpL[slide[x.first]][x.first] < x.second) {
slide[x.first] = i;
}
}
}
assert(false);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |