Submission #523970

# Submission time Handle Problem Language Result Execution time Memory
523970 2022-02-08T13:31:03 Z mateigg4 Table Tennis (info1cup20_tabletennis) C++14
87 / 100
3000 ms 4292 KB
#include <bits/stdc++.h>
#define nmax 160000
#define int long long
 
using namespace std;
 
int v[nmax + 1];
pair<int, int> sol[nmax + 1];
unordered_map<int, int> f;
 
signed main()
{
    //ifstream cin("tabletennis.in");
    //ofstream cout("tabletennis.out");
    int n, k, i, j, x, y, st, dr, s, p;
    cin >> n >> k;
    for (i = 1; i <= n + k; i++)
        cin >> v[i];
    sort(v + 1, v + n + k + 1);
    for (x = 0; x <= 2 * k; x++)
        for (y = n + k + 1; y > n - k; y--)
        {
            if (x + n + k - y <= k && f[v[x + 1] + v[y - 1]] == 0)
            {
                s = v[x + 1] + v[y - 1];
                // cout << s << endl;
                p = 0;
                st = x + 1, dr = y - 1;
                for (i = st; i <= dr; i++)
                {
                    while (dr > i && v[i] + v[dr] > s)
                        dr--;
                    if (v[i] + v[dr] == s)
                    {
                        sol[p++] = {v[i], v[dr]};
                        // cout << v[i] << " " << v[dr] << endl;
                    }
                }
                if (p >= n / 2)
                {
                    for (i = 0; i < n / 2; i++)
                        cout << sol[i].first << " ";
                    for (i = n / 2 - 1; i >= 0; i--)
                        cout << sol[i].second << " ";
                    return 0;
                }
                f[s]++;
            }
            else
                break;
        }
    return 0;
}

Compilation message

tabletennis.cpp: In function 'int main()':
tabletennis.cpp:15:18: warning: unused variable 'j' [-Wunused-variable]
   15 |     int n, k, i, j, x, y, st, dr, s, p;
      |                  ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 844 KB Output is correct
2 Correct 77 ms 4256 KB Output is correct
3 Correct 71 ms 4164 KB Output is correct
4 Correct 71 ms 4168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 4036 KB Output is correct
2 Correct 74 ms 4224 KB Output is correct
3 Correct 70 ms 4136 KB Output is correct
4 Correct 70 ms 4124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 206 ms 4248 KB Output is correct
3 Correct 76 ms 4292 KB Output is correct
4 Correct 102 ms 4096 KB Output is correct
5 Correct 71 ms 4164 KB Output is correct
6 Correct 76 ms 4164 KB Output is correct
7 Correct 92 ms 4256 KB Output is correct
8 Correct 71 ms 4120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Execution timed out 3074 ms 2040 KB Time limit exceeded
3 Halted 0 ms 0 KB -