fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. int main(){
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. cout.tie(0);
  8. int n,k,sum=0;
  9. cin>>n>>k;
  10. vector<int> v(n+5);
  11. int freq1[100005]={0},freq2[100005]={0};
  12. for(int i=0;i<n;i++){
  13. cin>>v[i];
  14. if(v[i]<=100000){
  15. freq1[v[i]]++;
  16. }
  17. if(v[i]>100000){
  18. freq2[v[i]-100000]++;
  19. }
  20. }
  21. for(int i=0;i<n;i++){
  22. for(int j=i+1;j<n;j++){
  23. if((v[i]+v[j])%k==0||(k%(v[i]+v[j])==0)){
  24. if(v[i]>100000&&v[j]>100000){
  25. if(v[i]==v[j]){
  26. if(freq2[v[i]-100000]>=2){
  27. sum+=2;
  28. freq2[v[i]-100000]--;
  29. freq2[v[j]-100000]--;
  30. // cout<<v[i]<<" "<<v[j]<<" ";
  31. break;
  32. }
  33. }
  34. else if(freq2[v[i]-100000]>0&&freq2[v[j]-100000]>0){
  35. sum+=2;
  36. freq2[v[i]-100000]--;
  37. freq2[v[j]-100000]--;
  38. // cout<<v[i]<<" "<<v[j]<<" ";
  39. break;
  40. }
  41. }
  42. if(v[i]<=100000&&v[j]<=100000){
  43. if(v[i]==v[j]){
  44. if(freq1[v[i]]>=2){
  45. sum+=2;
  46. freq1[v[i]]--;
  47. freq1[v[j]]--;
  48. // cout<<v[i]<<" "<<v[j]<<" ";
  49. break;
  50. }
  51. }
  52. else if(freq1[v[i]]>0&&freq1[v[j]]>0){
  53. sum+=2;
  54. freq1[v[i]]--;
  55. freq1[v[j]]--;
  56. // cout<<v[i]<<" "<<v[j]<<" ";
  57. break;
  58. }
  59. }
  60. else if(v[i]>100000&&v[j]<=100000){
  61. if(freq2[v[i]-100000]>0&&freq1[v[j]]>0){
  62. sum+=2;
  63. freq2[v[i]-100000]--;
  64. freq1[v[j]]--;
  65. // cout<<v[i]<<" "<<v[j]<<" ";
  66. break;
  67. }
  68. }
  69. else if(v[i]<=100000&&v[j]>100000){
  70. if(freq1[v[i]]>0&&freq2[v[j]-100000]>0){
  71. sum+=2;
  72. freq1[v[i]]--;
  73. freq2[v[j]-100000]--;
  74. // cout<<v[i]<<" "<<v[j]<<" ";
  75. break;
  76. }
  77. }
  78. }
  79. }
  80. }
  81. cout<<sum;
  82. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty