답안 #366233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
366233 2021-02-13T15:15:07 Z Ahmad_Hasan Table Tennis (info1cup20_tabletennis) C++17
87 / 100
3000 ms 12516 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);

    unordered_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));
    int cr=1;
    for(int i=0;i<nn&&i<k+2;i++){
        for(int j=nn-1;j>=0&&(nn-1-j)<=k+2;j--){
            if(!mp[v[i]+v[j]]){
                mp[v[i]+v[j]]=cr++;
            }
        }
    }
    int mxi=0;
    int f=0;
    for(unordered_map<int,int>::iterator it=mp.begin();it!=mp.end()&&!f;it++){
        for(int i=0;i<nn;i++){
            vector<int>::iterator it2=lower_bound(v.begin(),v.end(),(it->first)-v[i]);
            if(it2==v.end()||*it2!=(it->first)-v[i])continue;
            int vl=it2-v.begin();
            if(vl>i){
                pos[it->second].push_back({i,vl});
                if(pos[it->second].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:48:42: 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]
   48 |                 if(pos[it->second].size()>=n/2){
      |                    ~~~~~~~~~~~~~~~~~~~~~~^~~~~
tabletennis.cpp:64: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]
   64 |     for(int i=0;i<pos.size();i++)
      |                 ~^~~~~~~~~~~
tabletennis.cpp:69: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]
   69 |     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++)
      |                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1520 KB Output is correct
2 Correct 127 ms 5732 KB Output is correct
3 Correct 56 ms 5472 KB Output is correct
4 Correct 69 ms 5472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 6880 KB Output is correct
2 Correct 139 ms 5476 KB Output is correct
3 Correct 174 ms 6492 KB Output is correct
4 Correct 71 ms 5524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1004 KB Output is correct
2 Correct 33 ms 1416 KB Output is correct
3 Correct 20 ms 1132 KB Output is correct
4 Correct 23 ms 1260 KB Output is correct
5 Correct 37 ms 1260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 10 ms 620 KB Output is correct
3 Correct 10 ms 512 KB Output is correct
4 Correct 7 ms 492 KB Output is correct
5 Correct 12 ms 748 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2965 ms 5976 KB Output is correct
3 Correct 1289 ms 5660 KB Output is correct
4 Correct 610 ms 7540 KB Output is correct
5 Correct 885 ms 5764 KB Output is correct
6 Correct 60 ms 7888 KB Output is correct
7 Correct 2056 ms 9012 KB Output is correct
8 Correct 911 ms 9980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 413 ms 9232 KB Output is correct
2 Execution timed out 3094 ms 12516 KB Time limit exceeded
3 Halted 0 ms 0 KB -