Submission #1230577

#TimeUsernameProblemLanguageResultExecution timeMemory
1230577lopkusTable Tennis (info1cup20_tabletennis)C++20
100 / 100
47 ms2888 KiB
#include <bits/stdc++.h>

using namespace std;
#define MAXN 150000
#define MAXK 400
int v[MAXN + MAXK], f[MAXN + MAXK];
int nr;
char verif(int st, int dr, int k, int n2) {
    int i, j, s;
    f[st] = f[dr] = nr;
    s = v[st] + v[dr];
    i = st + 1;
    j = dr - 1;
    while (k >= 0 && i < j) {
        if (v[i] + v[j] < s) {
            i++;
            k--;
        } else if (v[i] + v[j] > s) {
            j--;
            k--;
        } else {
            if (n2 > 0) {
                f[i] = f[j] = nr;//le pastrez in solutie
                n2 -= 2;
            }
            i++;
            j--;
        }
    }
    return (k >= 0);//daca returneaza 1 am gasit o solutie
}
int main()
{
    int n, k, i, j, rez, n2;
    scanf("%d%d", &n, &k);
    n2 = n;
    n += k;
    for (i = 0; i < n; i++) {
        scanf("%d", &v[i]);
    }
    //trebuie sa sterg k, deci capetele st si dr vor fi sigur din primele k + 1 si ultimele k + 1
    //O(k^2 * n)
    i = rez = 0;
    while (i <= k && rez == 0) {
        j = 0;
        while (j <= k - i && rez == 0) {
            nr++;
            rez = verif(i, n - 1 - j, k - i - j, n2 - 2);//pozitiile st dr care sunt fixate si cate trebuei se elimin de la st + 1 la dr - 1
            j++;
        }
        i++;
    }
    for (i = 0; i < n; i++) {
        if (f[i] == nr) {
            printf("%d ", v[i]);
        }
    }
    fputc('\n', stdout);
    return 0;
}

Compilation message (stderr)

tabletennis.cpp: In function 'int main()':
tabletennis.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     scanf("%d%d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~
tabletennis.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         scanf("%d", &v[i]);
      |         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...