Submission #679439

#TimeUsernameProblemLanguageResultExecution timeMemory
679439alexddTable Tennis (info1cup20_tabletennis)C++17
72 / 100
3085 ms329908 KiB
#pragma GCC optimize("O3,unroll-loops") #include<bits/stdc++.h> using namespace std; #define int long long int n,k; unordered_map<int,int> fr; unordered_map<int,int> fr1; int mxm,unde; int a[160001]; vector<int> rez; void npat() { for(int i=1;i<=n+k;i++) { for(int j=1;j<i;j++) { fr[a[i]+a[j]]++; if(fr[a[i]+a[j]] > mxm) { mxm = fr[a[i]+a[j]]; unde = a[i]+a[j]; } } } for(int i=1;i<=n+k;i++) { if(a[i]<unde-a[i] && fr1[unde-a[i]]>0 && rez.size()<n) { rez.push_back(a[i]); rez.push_back(unde-a[i]); } } sort(rez.begin(),rez.end()); for(int i=0;i<n;i++) cout<<rez[i]<<" "; } bool verif(int unde) { int cnt=0; for(int i=1;i<=n+k;i++) { if(a[i]<unde-a[i] && fr1[unde-a[i]]>0) { cnt+=2; } } if(cnt>=n) return 1; return 0; } void afiseaza(int unde) { for(int i=1;i<=n+k;i++) { if(a[i]<unde-a[i] && fr1[unde-a[i]]>0 && rez.size()<n) { rez.push_back(a[i]); rez.push_back(unde-a[i]); } } sort(rez.begin(),rez.end()); for(int i=0;i<n;i++) cout<<rez[i]<<" "; } signed main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>k; for(int i=1;i<=n+k;i++) { cin>>a[i]; fr1[a[i]]++; } if(n<=2000) npat(); else { sort(a+1,a+1+n+k); for(int i=0;i<=k;i++) { for(int j=0;i+j<=k;j++) { if(verif(a[i+1]+a[n+k-j])) { afiseaza(a[i+1]+a[n+k-j]); return 0; } } } } return 0; } /** */

Compilation message (stderr)

tabletennis.cpp: In function 'void npat()':
tabletennis.cpp:27:60: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   27 |         if(a[i]<unde-a[i] && fr1[unde-a[i]]>0 && rez.size()<n)
      |                                                  ~~~~~~~~~~^~
tabletennis.cpp: In function 'void afiseaza(long long int)':
tabletennis.cpp:55:60: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   55 |         if(a[i]<unde-a[i] && fr1[unde-a[i]]>0 && rez.size()<n)
      |                                                  ~~~~~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...