이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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];
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> K;
FOR(i,1,N+K){
cin >> A[i];
}
FOR(i,1,K+1){
RFOR(j,N+K,N+i-1){
int mx = min(j-i+1-N, K-(i-1)-(N+K-j));
//TRACE(i _ j _ mx);
int l = i, r = j;
int a = i+1, b = j-1, c = 0;
vector<int> ls = {l}, rs = {r};
while (SZ(ls)+SZ(rs) < N && a < b && c <= mx) {
int cur = A[a]+A[b], tgt = A[l]+A[r];
//TRACE(a _ b _ cur _ tgt);
if (cur == tgt) {
l = a, r = b;
ls.push_back(a++);
rs.push_back(b--);
} else {
if (cur < tgt) ++a, ++c;
else --b, ++c;
}
}
//TRACE(SZ(ls) _ SZ(rs) _ c);
if (SZ(ls)+SZ(rs) == N) {
for (int& x : ls) cout << A[x] << ' ';
reverse(ALL(rs));
for (int& x : rs) cout << A[x] << ' ';
return 0;
}
}
}
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... |