Submission #687670

#TimeUsernameProblemLanguageResultExecution timeMemory
687670vlad_TTTable Tennis (info1cup20_tabletennis)C++17
87 / 100
3076 ms22716 KiB
#include <iostream> #include <algorithm> #include <unordered_map> #include <vector> using namespace std; long long v[150405]; long long sol[150405]; unordered_map <long long,long long> f; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n,k,suma; cin>>n>>k; for(int i=1;i<=n+k;i++) { cin>>v[i]; f[v[i]]+=1; } if (n + k <= 18) {///Vlad e prea bun for (int mask = 1; mask < (1 << (n + k)); mask++) { if (__builtin_popcount(mask) == n) { vector<int> pos; for (int bit = 0; bit < n + k; bit++) { if (mask & (1 << bit)) pos.push_back(v[bit + 1]); } bool ok = 1; for (int i = 1; i < (n / 2); i++) { if (pos[i] + pos[n - i - 1] != pos[0] + pos[n - 1]) { ok = false; } } if (ok) { for (auto &it : pos) { cout << it << " "; } return 0; } } } } else if(k==1) {///macar 20 de puncte ///cazul in care nu eliminam nici 1, nici n+k ///sort(v+1,v+k+n); suma=v[1]+v[n+k]; int eliminat,cnteliminat=0; ///cout<<"suma="<<suma<<"\n"; for(int i=2;i<n+k;i++) { if(f[suma-v[i]]==0||v[i]*2==suma) { cnteliminat++; ///cout<<"nu merge "<<v[i]<<"\n"; eliminat=v[i]; } } if(cnteliminat==1) { for(int i=1;i<=n+k;i++) { if(f[suma-v[i]]==1&&v[i]*2!=suma) cout<<v[i]<<" "; } } else { ///eliminam pe primul numar cnteliminat=0; suma=v[2]+v[n+k]; for(int i=2;i<n+k;i++) { if(f[suma-v[i]]==0||v[i]*2==suma) { cnteliminat++; ///cout<<"nu merge "<<v[i]<<"\n"; eliminat=v[i]; } } if(cnteliminat==0) { for(int i=2;i<=n+k;i++) cout<<v[i]<<" "; } else { for(int i=1;i<n+k;i++) cout<<v[i]<<" "; } } return 0; } ///cout<<"n^3\n"; int cntok=0,ok=0; for (int i = 1; i <= k+1; i++) { for (int j = i + n-1; j <=n+k; j++) { suma=v[i]+v[j]; cntok = 0; vector<pair<int, int>> output; int ptr1 = i, ptr2 = j; while (ptr1 < ptr2) { if (v[ptr1] + v[ptr2] == suma) { output.push_back({v[ptr1], v[ptr2]}); cntok++; ptr1++; ptr2--; } else if (v[ptr1] + v[ptr2] < suma) { ptr1++; } else { ptr2--; } } if(cntok>=n / 2) { for (int i = 0; i < n / 2; i++) { sol[i] = output[i].first; sol[n - i - 1] = output[i].second; } for(int l=0;l<n;l++) cout<<sol[l]<<" "; return 0; } if(ok==1) break; } if(ok==1) break; } return 0; }

Compilation message (stderr)

tabletennis.cpp: In function 'int main()':
tabletennis.cpp:50:13: warning: variable 'eliminat' set but not used [-Wunused-but-set-variable]
   50 |         int eliminat,cnteliminat=0;
      |             ^~~~~~~~
#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...