Submission #845928

# Submission time Handle Problem Language Result Execution time Memory
845928 2023-09-06T19:55:11 Z samekkk Table Tennis (info1cup20_tabletennis) C++14
87 / 100
3000 ms 4796 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a,b) for (int a = 0; a < (b); ++a)
#define pb push_back
#define all(t) t.begin(), t.end()

const int max_N = 160005;
int n = 0, k = 0;
int A[max_N];
vector<int> V;
vector<int> wyn;

inline bool czy_pasuje(int val1, int val2)
{
    if (val1 == val2) return false;
    wyn = vector<int>();
    wyn.pb(val1), wyn.pb(val2);
    if (n == 2) return true;
    vector<int> vect;
    rep(i,n+k) if (A[i] != val1 and A[i] != val2) vect.pb(A[i]);
    int sum = val1 + val2, lewy_wsk = 0, prawy_wsk = vect.size()-1;
    while(lewy_wsk < prawy_wsk)
    {
        if(vect[lewy_wsk] == val1 or vect[lewy_wsk] == val2) ++lewy_wsk;
        if(vect[prawy_wsk] == val1 or vect[prawy_wsk] == val2) --prawy_wsk;
        if(vect[lewy_wsk] == val1 or vect[lewy_wsk] == val2 or vect[prawy_wsk] == val1 or vect[prawy_wsk] == val2) continue;
        if (vect[lewy_wsk] + vect[prawy_wsk] == sum)
        {
            wyn.pb(vect[lewy_wsk]), wyn.pb(vect[prawy_wsk]);
            if (n == wyn.size()) return true;
            ++lewy_wsk, --prawy_wsk;
        }
        else if (vect[lewy_wsk] + vect[prawy_wsk] > sum) --prawy_wsk;
        else ++lewy_wsk;
    }
    return false;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> k;
    rep(i,n+k) cin >> A[i];
    rep(i,k+1) V.pb(A[i]);
    for (int i = n-1; i < n+k; ++i) V.pb(A[i]);
    rep(i,V.size())
    {
        for (int j = i+1; j < V.size(); ++j)
        {
            if (czy_pasuje(V[i],V[j]) == true)
            {
                sort(all(wyn));
                for (auto v : wyn) cout << v << ' ';
                cout << '\n';
                return 0;
            }
        }
    }
    return 0;
}

Compilation message

tabletennis.cpp: In function 'bool czy_pasuje(int, int)':
tabletennis.cpp:31:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |             if (n == wyn.size()) return true;
      |                 ~~^~~~~~~~~~~~~
tabletennis.cpp: In function 'int main()':
tabletennis.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(a,b) for (int a = 0; a < (b); ++a)
      |                                    ^
tabletennis.cpp:50:5: note: in expansion of macro 'rep'
   50 |     rep(i,V.size())
      |     ^~~
tabletennis.cpp:52:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for (int j = i+1; j < V.size(); ++j)
      |                           ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 872 KB Output is correct
2 Correct 38 ms 4636 KB Output is correct
3 Correct 27 ms 4480 KB Output is correct
4 Correct 27 ms 4744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 4536 KB Output is correct
2 Correct 27 ms 4796 KB Output is correct
3 Correct 36 ms 4728 KB Output is correct
4 Correct 31 ms 4504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 16 ms 500 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 10 ms 344 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 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 4 ms 604 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 3 ms 480 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 613 ms 4688 KB Output is correct
3 Correct 47 ms 4636 KB Output is correct
4 Correct 288 ms 4752 KB Output is correct
5 Correct 67 ms 4528 KB Output is correct
6 Correct 186 ms 4768 KB Output is correct
7 Correct 284 ms 4796 KB Output is correct
8 Correct 53 ms 4616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Execution timed out 3030 ms 3104 KB Time limit exceeded
3 Halted 0 ms 0 KB -