Submission #377651

# Submission time Handle Problem Language Result Execution time Memory
377651 2021-03-14T15:21:34 Z wildturtle Table Tennis (info1cup20_tabletennis) C++14
87 / 100
3000 ms 53000 KB
#include<bits/stdc++.h>
using namespace std;
long long n,k,cnt,A[500005];
map <long long,long long> mp,mp1;
vector <long long> v,st,v1;
long long check(long long sum) {
    for(long long i=1;i<=n;i++) mp1[A[i]]++;
    cnt=0; v.clear(); v1.clear();
    for(long long i=1;i<=n;i++) {
        if(mp1[A[i]]==0) continue;
        mp1[A[i]]--;
        if(mp1[sum-A[i]]>=1) {
            cnt++; mp1[sum-A[i]]=0; 
            v.push_back(A[i]);
            v1.push_back(sum-A[i]);
            if(cnt==(n-k)/2) break;
        }
    }
    mp1.clear();
    if(cnt>=(n-k)/2) return 1;
    else return 0;
}
int main() {
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>n>>k;
    n+=k;
    for(long long i=1;i<=n;i++) {
        cin>>A[i];
    }
    sort(A+1,A+1+n);
    if(n>=4*k) {
        for(long long i=1;i<=2*k;i++) {
            for(long long j=n-2*k+1;j<=n;j++) {
                mp[A[i]+A[j]]++;
                if(mp[A[i]+A[j]]>=k) st.push_back(A[i]+A[j]);
            }
        }
        for(long long i=0;i<st.size();i++) {
            if(check(st[i])) break;
        }
        for(long long i=0;i<v.size();i++)
        cout<<v[i]<<" ";
        for(long long i=v1.size()-1;i>=0;i--)
        cout<<v1[i]<<" ";
    }
    else {
        for(long long i=1;i<=k;i++) {
            for(long long j=n-k+i-1;j<=n;j++) {
                st.push_back(A[i]+A[j]);
            }
        }
        for(long long i=0;i<st.size();i++) {
            if(check(st[i])) break;
        }
        for(long long i=0;i<v.size();i++)
        cout<<v[i]<<" ";
        for(long long i=v1.size()-1;i>=0;i--)
        cout<<v1[i]<<" ";
    }
}

Compilation message

tabletennis.cpp: In function 'int main()':
tabletennis.cpp:38:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for(long long i=0;i<st.size();i++) {
      |                           ~^~~~~~~~~~
tabletennis.cpp:41:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         for(long long i=0;i<v.size();i++)
      |                           ~^~~~~~~~~
tabletennis.cpp:52:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for(long long i=0;i<st.size();i++) {
      |                           ~^~~~~~~~~~
tabletennis.cpp:55:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(long long i=0;i<v.size();i++)
      |                           ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 620 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 2308 KB Output is correct
2 Correct 320 ms 21892 KB Output is correct
3 Correct 110 ms 13772 KB Output is correct
4 Correct 108 ms 13784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 194 ms 18912 KB Output is correct
2 Correct 108 ms 13784 KB Output is correct
3 Correct 279 ms 20584 KB Output is correct
4 Correct 107 ms 13784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 255 ms 504 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 188 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 8 ms 620 KB Output is correct
3 Correct 3 ms 620 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 4 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 112 ms 13912 KB Output is correct
3 Correct 316 ms 21868 KB Output is correct
4 Correct 889 ms 21548 KB Output is correct
5 Correct 1133 ms 23224 KB Output is correct
6 Correct 392 ms 13912 KB Output is correct
7 Correct 1002 ms 22356 KB Output is correct
8 Correct 1247 ms 22440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1516 KB Output is correct
2 Correct 515 ms 50752 KB Output is correct
3 Correct 472 ms 53000 KB Output is correct
4 Correct 366 ms 47516 KB Output is correct
5 Execution timed out 3031 ms 28512 KB Time limit exceeded
6 Halted 0 ms 0 KB -