Submission #423625

# Submission time Handle Problem Language Result Execution time Memory
423625 2021-06-11T10:34:49 Z lyc Table Tennis (info1cup20_tabletennis) C++14
0 / 100
3000 ms 59076 KB
#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 == 1) {
        cout << A[1] << '\n';
        return 0;
    } else 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 << 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
1 Runtime error 51 ms 59076 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 36336 KB Output not subsequence of input
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3073 ms 29016 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 30156 KB Output not subsequence of input
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 28412 KB Output not subsequence of input
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 49 ms 57708 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 55 ms 57704 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 94 ms 45628 KB Output not subsequence of input
2 Halted 0 ms 0 KB -