Submission #377655

# Submission time Handle Problem Language Result Execution time Memory
377655 2021-03-14T15:41:38 Z wildturtle Table Tennis (info1cup20_tabletennis) C++14
87 / 100
3000 ms 52956 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;
long long check(long long sum) {
    for(long long i=1;i<=n;i++) mp1[A[i]]++;
    cnt=0; v.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]);
            v.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);
    scanf( "%d", &n );
    scanf( "%d", &k ); 
    n+=k;
    for(long long i=1;i<=n;i++) {
        scanf( "%d", &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;
        }
        sort(v.begin(),v.end());
        for(long long i=0;i<v.size();i++)
        printf ("%d ", v[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;
        }
        sort(v.begin(),v.end());
        for(long long i=0;i<v.size();i++)
        printf ("%d ", v[i]);
    }
}

Compilation message

tabletennis.cpp: In function 'int main()':
tabletennis.cpp:25:14: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   25 |     scanf( "%d", &n );
      |             ~^   ~~
      |              |   |
      |              |   long long int*
      |              int*
      |             %lld
tabletennis.cpp:26:14: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   26 |     scanf( "%d", &k );
      |             ~^   ~~
      |              |   |
      |              |   long long int*
      |              int*
      |             %lld
tabletennis.cpp:29:18: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   29 |         scanf( "%d", &A[i] );
      |                 ~^   ~~~~~
      |                  |   |
      |                  |   long long int*
      |                  int*
      |                 %lld
tabletennis.cpp:39: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]
   39 |         for(long long i=0;i<st.size();i++) {
      |                           ~^~~~~~~~~~
tabletennis.cpp:43: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]
   43 |         for(long long i=0;i<v.size();i++)
      |                           ~^~~~~~~~~
tabletennis.cpp:44:19: warning: format '%d' expects argument of type 'int', but argument 2 has type '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} [-Wformat=]
   44 |         printf ("%d ", v[i]);
      |                  ~^
      |                   |
      |                   int
      |                  %lld
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:56: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]
   56 |         for(long long i=0;i<v.size();i++)
      |                           ~^~~~~~~~~
tabletennis.cpp:57:19: warning: format '%d' expects argument of type 'int', but argument 2 has type '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} [-Wformat=]
   57 |         printf ("%d ", v[i]);
      |                  ~^
      |                   |
      |                   int
      |                  %lld
tabletennis.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |     scanf( "%d", &n );
      |     ~~~~~^~~~~~~~~~~~
tabletennis.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |     scanf( "%d", &k );
      |     ~~~~~^~~~~~~~~~~~
tabletennis.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |         scanf( "%d", &A[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 2300 KB Output is correct
2 Correct 331 ms 21996 KB Output is correct
3 Correct 123 ms 13664 KB Output is correct
4 Correct 125 ms 13664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 18920 KB Output is correct
2 Correct 123 ms 13796 KB Output is correct
3 Correct 289 ms 20460 KB Output is correct
4 Correct 120 ms 13688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 261 ms 508 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 189 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 27 ms 364 KB Output is correct
2 Correct 9 ms 620 KB Output is correct
3 Correct 2 ms 620 KB Output is correct
4 Correct 167 ms 620 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 4 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 123 ms 13792 KB Output is correct
3 Correct 934 ms 21756 KB Output is correct
4 Correct 910 ms 21212 KB Output is correct
5 Correct 1179 ms 23112 KB Output is correct
6 Correct 413 ms 13792 KB Output is correct
7 Correct 1040 ms 22204 KB Output is correct
8 Correct 1263 ms 22236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1516 KB Output is correct
2 Correct 570 ms 50624 KB Output is correct
3 Correct 516 ms 52956 KB Output is correct
4 Correct 382 ms 47584 KB Output is correct
5 Execution timed out 3054 ms 28640 KB Time limit exceeded
6 Halted 0 ms 0 KB -