Submission #862463

# Submission time Handle Problem Language Result Execution time Memory
862463 2023-10-18T09:38:28 Z AtabayRajabli Table Tennis (info1cup20_tabletennis) C++17
87 / 100
3000 ms 6072 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

// author : AtabeyR

#define pb          push_back
#define pii         pair<int, int>
#define pll         pair<ll, ll>
#define all(v)      v.begin(), v.end()
#define OPT         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define sec         second
#define fi          first
#define int         ll
#define print(k)    cerr << "Ans : "; cout << k << endl;
#define ins         insert
#define bpc         __builtin_popcountll
#define skip        continue
#define endll        '\n'
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)   a*b / (__gcd(a, b))

typedef long long ll;
typedef unsigned long long ull;
const int oo = 0x3F3F3F3F;
const int ooo = 0x3F3F3F3F3F3F3F3FLL;
const int mod = 998244353;
const int sz = 2e5;
using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;

void open(string s)
{
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

int n, m, k, a[sz];

bool f(int start, int end, int rem)
{   

    int s = start, e = end, ls = s, rs = e, team = 1;
    s++;
    e--;
    
    while(s < e)
    {
        if(a[s] - a[ls] < a[rs] - a[e])
        {
            rem--;
            s++;
        }
        else if(a[s] - a[ls] > a[rs] - a[e])
        {
            rem--;
            e--;
        }
        else
        {
            ls = s;
            rs = e;
            s++;
            e--;
            team++;
        }
        if(rem < 0 || team > n / 2)break;
    }
    if(rem || team > n/2)return 0;

    s = start + 1;
    e = end - 1;
    ls = start;
    rs = end;

    vector<int> l, r;

    l.pb(a[ls]);
    r.pb(a[rs]);

    while(s < e)
    {
        if(a[s] - a[ls] < a[rs] - a[e])
        {
            rem--;
            s++;
        }
        else if(a[s] - a[ls] > a[rs] - a[e])
        {
            rem--;
            e--;
        }
        else
        {
            ls = s;
            rs = e;
            l.pb(a[ls]);
            r.pb(a[rs]);
            s++;
            e--;
        }
    }


    for(int i : l)cout << i << " ";
    for(auto it = r.rbegin(); it != r.rend(); it++)cout << *it << " ";
    return 1;
}

void solve()
{
    cin >> n >> k;

    for(int i = 1; i<=n+k; i++)cin >> a[i];

    for(int i = 0; i<=k; i++)
    {
        for(int j = 0; j<=i; j++)
        {
            if(j+1 < n + k - (i - j) && f(j+1, n+k-(i-j), k-i))return;
        }
    }
}

int32_t main()  
{
    // open("i");

    OPT
    int t = 1;
    // cin >> t;

    for(int i = 1; i<=t; i++)
        solve();
}

Compilation message

tabletennis.cpp: In function 'void open(std::string)':
tabletennis.cpp:35:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tabletennis.cpp:36:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1116 KB Output is correct
2 Correct 23 ms 5820 KB Output is correct
3 Correct 21 ms 5832 KB Output is correct
4 Correct 22 ms 5832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 5820 KB Output is correct
2 Correct 21 ms 5820 KB Output is correct
3 Correct 21 ms 5788 KB Output is correct
4 Correct 21 ms 5820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 21 ms 5804 KB Output is correct
3 Correct 22 ms 5832 KB Output is correct
4 Correct 21 ms 6072 KB Output is correct
5 Correct 25 ms 5820 KB Output is correct
6 Correct 30 ms 5768 KB Output is correct
7 Correct 23 ms 5828 KB Output is correct
8 Correct 25 ms 5832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 344 KB Output is correct
2 Correct 30 ms 6012 KB Output is correct
3 Correct 40 ms 5728 KB Output is correct
4 Correct 31 ms 5824 KB Output is correct
5 Correct 26 ms 5820 KB Output is correct
6 Execution timed out 3022 ms 3020 KB Time limit exceeded
7 Halted 0 ms 0 KB -