Submission #697028

# Submission time Handle Problem Language Result Execution time Memory
697028 2023-02-08T00:28:34 Z hazzle Table Tennis (info1cup20_tabletennis) C++17
24 / 100
3000 ms 2372 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define all(m) (m).begin(), (m).end()
#define rall(m) (m).rbegin(), (m).rend()
#define vec vector
#define sz(a) (int) (a).size()
#define mpp make_pair
#define mtt make_tuple

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tui;

template <typename T> bool umin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> bool umax(T &a, T b) { return a < b ? a = b, 1 : 0; }

mt19937 rng((uint64_t) new char);

int solve(){
        int n, k;
        cin >> n >> k;
        int z = n + k;
        vec <int> a(z);
        for (auto &i: a) cin >> i;

        auto ok = [&](int ai, int x){
                if (2 * ai == x) return false;
                int p = lower_bound(all(a), x - ai) - a.begin();
                return p != z && a[p] + ai == x;
        };

        auto get_ans = [&](int x){
                vec <int> ans;
                int pl = 0, pr = z - 1;
                while(sz(ans) < n){
                        if (a[pl] + a[pr] == x){
                                ans.push_back(a[pl]);
                                ans.push_back(a[pr]);
                                ++pl, --pr;
                        }
                        else if (a[pl] + a[pr] < x) ++pl;
                        else --pr;
                }
                sort(all(ans));
                for (auto &i: ans) cout << i << " ";
                exit(0);
        };

        if (n <= k){
                for (int i = 0; i < z; ++i){
                        for (int j = i + 1; j < z; ++j){
                                int x = a[i] + a[j];
                                int cnt = 0;
                                for (int l = 0; l < z; ++l){
                                        cnt += ok(a[l], x);
                                }
                                if (cnt >= n) get_ans(x);
                        }
                }
                return 0;
        }

        while(true){
                int ai = a[rng() % z];
                for (auto &aj: a){
                        int x = ai + aj, cnt = 0;
                        for (int i = 0; i < min(n, 2 * k + 1); ++i){
                                cnt += ok(a[i], x);
                        }
                        if (cnt >= min(n, 2 * k + 1)) get_ans(x);
                }
        }

        return 0;
}

signed main(){
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int tst = 1; //cin >> tst;
        while(tst--) solve();
        return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 3041 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 980 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3055 ms 2372 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 35 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 17 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 3070 ms 340 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 3068 ms 2308 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 3048 ms 2316 KB Time limit exceeded
3 Halted 0 ms 0 KB -