Submission #493947

# Submission time Handle Problem Language Result Execution time Memory
493947 2021-12-13T13:10:22 Z balbit Table Tennis (info1cup20_tabletennis) C++14
0 / 100
3000 ms 2252 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first
#define s second
#define pii pair<ll, ll>

#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define MX(a,b) a = max(a,b)
#define MN(a,b) a = min(a,b)

#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
#define pb push_back

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do( T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do( T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT

const int maxn = 2e5+5;

int a[maxn];
int n, k;

unordered_set<int> tried;
void get(int sum);
bool test(int sum) {
    if (tried.count(sum)) return 0;
    int lp = 0, rp = n-1;
    int imp = 0;

    while (lp < rp && imp <= k) {
        if (a[lp] + a[rp] == sum) {
            ++lp; --rp;
        }else if (a[lp] + a[rp] < sum) {
            ++lp; ++imp;
        }else{
            --rp; ++imp;
        }
    }

    if (imp > k) {
        tried.insert(sum);
        return 0;
    }
    get(sum);
    return 1;
}


void get(int sum) {
    int lp = 0, rp = n-1;
    vector<int> ret;
    while (lp < rp) {
        if (a[lp] + a[rp] == sum) {
            ret.pb(lp); ret.pb(rp);
            ++lp; --rp;
        }else if (a[lp] + a[rp] < sum) {
            ++lp;
        }else{
            --rp;
        }
    }

    sort(ALL(ret));
    for (int t : ret) cout<<t+1<<' ';
    cout<<endl;
    exit(0);
}


signed main(){
    ios::sync_with_stdio(0), cin.tie(0);

    bug(1,2);
    cin>>n>>k;
    REP(i,n) cin>>a[i];
    sort(a, a+n);

    if (n <= 30000) {
        // brute
        REP(i,n) {
            REP(j,k+1) {
                int to = n-i-1-j;
                if (i < to && test(a[i] + a[to])) {
//                    get(a[i] + a[to]);
                }
            }
        }
        assert(0);
    }

    while (1) {
        int i = rand() % n;
        int j = rand() % (k+1);
        int to = n-i-1-j;
        if (i < to && test(a[i] + a[to])) {

        }
    }


}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 848 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3092 ms 2252 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output not subsequence of input
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output not subsequence of input
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output not subsequence of input
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output not subsequence of input
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output not subsequence of input
2 Halted 0 ms 0 KB -