Submission #366246

# Submission time Handle Problem Language Result Execution time Memory
366246 2021-02-13T15:45:41 Z Ahmad_Hasan Table Tennis (info1cup20_tabletennis) C++17
87 / 100
3000 ms 43440 KB
#include <bits/stdc++.h>
#define int long long
/**
     ||||||||||       |||||     |||||    ||||||||||
    |||||||||||||     |||||     |||||  |||||
   ||||     ||||||    |||||     |||||  |||||
  |||||||||||||||||   |||||||||||||||    ||||||||||
 |||||||||||||||||||  |||||||||||||||           |||||
 |||||         |||||  |||||     |||||           |||||
 |||||         |||||  |||||     |||||    ||||||||||
AHMED;HASSAN;SAEED;
*/

using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);      cout.tie(0);
    int n,k;
    cin>>n>>k;
    vector<int>v(n+k);

    map<int,int >mp,mp2;
    int nn=n+k;
    for(int i=0;i<nn;i++){
        cin>>v[i];
    }

    vector<vector<pair<int,int> > >pos((k+5)*(k+5));
    vector<int>sums((k+5)*(k+5));
    int cr=0;
    for(int i=0;i<nn&&i<k+2;i++){
        for(int j=nn-1;j>=0&&(nn-1-j)<=k+2-i;j--){
            sums[cr++]=v[i]+v[j];
        }
    }
    sort(sums.begin(),sums.begin()+cr);
    int mxi=0;
    int f=0;
    for(int j=0;j<cr;j++){
        if(j<cr-1&&sums[j]==sums[j+1])continue;
        for(int i=0;i<nn;i++){
            vector<int>::iterator it2=lower_bound(v.begin(),v.end(),sums[j]-v[i]);
            if(it2==v.end()||*it2!=sums[j]-v[i])continue;
            int vl=it2-v.begin();
            if(vl>i){
                pos[j].push_back({i,vl});
                if(pos[j].size()>=n/2){
                    f=1;
                    break;
                }

            }
        }
    }
/**
    for(int i=0;i<pos.size();i++){
        for(int j=0;j<pos[i].size();j++){
            cout<<pos[i][j].first<<'-'<<pos[i][j].second<<' ';
        }
        cout<<'\n';
    }
*/
    for(int i=0;i<pos.size();i++)
        if(pos[i].size()>pos[mxi].size())
            mxi=i;
    vector<int>ans(n);
    int l=0,r=n-1;
    for(int i=0;i<pos[mxi].size()&&i<n/2;i++){
        ans[l]=(v[pos[mxi][i].first]);
        ans[r]=(v[pos[mxi][i].second]);
        l++;   r--;
    }
    for(int i=0;i<ans.size();i++)
        cout<<ans[i]<<' ';

    return 0;
}



/**
4 3
100000000000 200000000000 300000000000 400000000000 800000000000 1000000000000 2000000000000

*/

Compilation message

tabletennis.cpp: In function 'int32_t main()':
tabletennis.cpp:49:33: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   49 |                 if(pos[j].size()>=n/2){
      |                    ~~~~~~~~~~~~~^~~~~
tabletennis.cpp:65:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     for(int i=0;i<pos.size();i++)
      |                 ~^~~~~~~~~~~
tabletennis.cpp:70:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for(int i=0;i<pos[mxi].size()&&i<n/2;i++){
      |                 ~^~~~~~~~~~~~~~~~
tabletennis.cpp:75:18: 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]
   75 |     for(int i=0;i<ans.size();i++)
      |                 ~^~~~~~~~~~~
tabletennis.cpp:40:9: warning: variable 'f' set but not used [-Wunused-but-set-variable]
   40 |     int f=0;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 492 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 14 ms 1916 KB Output is correct
2 Correct 97 ms 5472 KB Output is correct
3 Correct 87 ms 5600 KB Output is correct
4 Correct 82 ms 5600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 120 ms 7276 KB Output is correct
2 Correct 140 ms 5472 KB Output is correct
3 Correct 138 ms 6136 KB Output is correct
4 Correct 113 ms 5480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 876 KB Output is correct
2 Correct 15 ms 876 KB Output is correct
3 Correct 19 ms 876 KB Output is correct
4 Correct 18 ms 876 KB Output is correct
5 Correct 21 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 21 ms 492 KB Output is correct
3 Correct 11 ms 492 KB Output is correct
4 Correct 12 ms 492 KB Output is correct
5 Correct 10 ms 492 KB Output is correct
6 Correct 6 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2211 ms 5636 KB Output is correct
3 Correct 1395 ms 5596 KB Output is correct
4 Correct 1819 ms 8028 KB Output is correct
5 Correct 1130 ms 5652 KB Output is correct
6 Correct 643 ms 43440 KB Output is correct
7 Correct 2147 ms 7752 KB Output is correct
8 Correct 1733 ms 8156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 672 ms 8172 KB Output is correct
2 Execution timed out 3055 ms 7296 KB Time limit exceeded
3 Halted 0 ms 0 KB -