Submission #791941

# Submission time Handle Problem Language Result Execution time Memory
791941 2023-07-24T12:43:47 Z Cookie Table Tennis (info1cup20_tabletennis) C++14
34 / 100
53 ms 5832 KB
#include<bits/stdc++.h>
#include<fstream>
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
//ifstream fin("FEEDING.INP");
//ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ll mxn = 2e5 + 5, base = 972663749;
const ll mod = 911382323, mxv = 1e9 + 1;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rr(ll l, ll r){
    return(uniform_int_distribution<ll>(l, r)(rng));
}
 
int n, k;
int a[mxn + 1];
vt<int>seg;
int check(int v, bool trace = 0){
    int l = 1, r = n + k, cnt = 0;
    while(l < r){
        if(a[l] + a[r] == v){
            if(trace && sz(seg) != n){
                seg.pb(a[l]); seg.pb(a[r]);
            }
            cnt++;
            l++; r--;
        }else if(a[l] + a[r] > v){
            r--;
        }else{
            l++;
        }
    }
    return(cnt);
}
signed main()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n + k; i++)cin >> a[i];
    sort(a + 1, a + n + k + 1);
    if(k * 4 < n){
    for(int tol = 1; tol <= k + 1; tol++){
        for(int tor = max(n, tol + 1); tor <= n + k; tor++){
        if(check(a[tol] + a[tor]) >= n / 2){
            check(a[tol] + a[tor], 1);
            break;
        }
        }
    }
    }else{
        map<int, int>sm;
        for(int i = 1; i <= k + k; i++){
            for(int j = n + k; j > n - k; j--){
                sm[a[i] + a[j]]++;
            }
        }
        vt<ll>cand;
        for(auto i: sm){
            if(i.se >= k){
                cand.pb(i.fi);
            }
        }
        for(auto i: cand){
            if(check(i) >= n / 2){
                check(i, 1);
                break;
            }
        }
    }
    
    sort(seg.begin(), seg.end());
    for(auto i: seg){
        cout << i << " ";
    }
    return(0);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 708 KB Output is correct
2 Correct 27 ms 3080 KB Output is correct
3 Correct 26 ms 3020 KB Output is correct
4 Correct 27 ms 3024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 3044 KB Output is correct
2 Correct 28 ms 3088 KB Output is correct
3 Correct 27 ms 3132 KB Output is correct
4 Correct 28 ms 3024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 724 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 1 ms 212 KB Unexpected end of file - int32 expected
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 53 ms 5832 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -