Submission #717373

#TimeUsernameProblemLanguageResultExecution timeMemory
717373MrM7mdTable Tennis (info1cup20_tabletennis)C++17
72 / 100
3062 ms330004 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' #define F first #define S second #define pb push_back #define all(a) a.begin(),a.end() const int N=1e5; const int off=(1<<20); const int MOD = 1e9+7; signed main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n,k; cin >> n >> k; int sz=n+k; int a[sz]; unordered_map<int,int>mp; for(int i=0;i<sz;i++){ cin >>a[i]; mp[a[i]]++; } sort(a,a+sz); if(k==1){ int f=a[sz/2]+a[sz/2-1],s=a[sz/2]+a[sz/2+1],t=a[0]+a[sz-1]; int x=0,y=0,z=0; // cout<<f<<' '<<s << ' '<<t<<endl; for(int i=0;i<sz;i++){ if(a[i]!=f-a[i]){ if(!mp[f-a[i]]){ if(x)x=-1; else x=a[i]; } } else{ x=a[i]; } if(a[i]!=s-a[i]){ if(!mp[s-a[i]]){ if(y)z=-1; else y=a[i]; } } else{ y=a[i]; } if(a[i]!=t-a[i]){ if(!mp[t-a[i]]){ if(z)z=-1; else z=a[i]; } } else{ z=a[i]; } } int ans=max({z,x,y}); for(int i=0;i<sz;i++){ if(a[i]!=ans)cout<<a[i]<<' '; } } else { vector<int>v; for(int i=0;i<=k;i++){ for(int j=0;j<=k-i;j++){ v.pb(a[i]+a[sz-j-1]); // cout<<v.back()<<' '; } } // cout<<v.size()<<endl; int h[v.size()]={0}; for(int i=0;i<sz;i++){ for(int j=0;j<v.size();j++){ if(a[i]!=v[j]-a[i]){ if(!mp[v[j]-a[i]]){ if(h[j]<k&&h[j]>=0)h[j]++; else h[j]=-1; } } else{ if(h[j]<k&&h[j]>=0)h[j]++; else h[j]=-1; } } } int ans; for(int i=0;i<v.size();i++){ if(h[i]>-1)ans=v[i]; // cout<<pp[i].F<<' '<<pp[i].S; } for(int i=0;i<sz;i++){ if(mp[ans-a[i]]&&ans-a[i]!=a[i])cout<<a[i]<<' '; } } } /* */

Compilation message (stderr)

tabletennis.cpp: In function 'int main()':
tabletennis.cpp:77:23: 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]
   77 |          for(int j=0;j<v.size();j++){
      |                      ~^~~~~~~~~
tabletennis.cpp:91:20: 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]
   91 |       for(int i=0;i<v.size();i++){
      |                   ~^~~~~~~~~
tabletennis.cpp:98:19: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   98 |          if(mp[ans-a[i]]&&ans-a[i]!=a[i])cout<<a[i]<<' ';
      |                ~~~^~~~~
#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...