ArfIsAToe

yosr we7let f problem so khdemtou bel C (longest distinct subarray )

Mar 3rd, 2021
660
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. void remp(int t[],int n)
  3. {
  4.     for (int a=0;a<n;a++)
  5.     {
  6.         scanf("%d",t+a);
  7.     }
  8. }
  9. int distinct(int t[],int a,int b)
  10. {
  11.     for (int x=a;x<b;x++)
  12.     {
  13.         if (t[x]==t[b])
  14.         {
  15.             a=x;
  16.             break;
  17.         }
  18.     }
  19.     return t[a]!=t[b];
  20. }
  21. int GetSubarray(int t[],int n)
  22. {
  23.     int max=0,sum=1;
  24.     for (int a=0;a<n;a++)
  25.     {
  26.         for (int b=a+1;b<n;b++)
  27.         {
  28.             if(!distinct(t,a,b))
  29.                 break;
  30.             sum++;
  31.         }
  32.         if (sum>max)
  33.             max=sum;
  34.         if (max>=n-a)
  35.             break;
  36.         sum=1;
  37.     }
  38.     return max;
  39. }
  40. int main()
  41. {
  42.     int n;
  43.     scanf("%d",&n);
  44.     int t[n];
  45.     remp(t,n);
  46.     printf("\n\n%d\n",GetSubarray(t,n));
  47. }
  48.  
  49. /*
  50. 8
  51. 5
  52. 1
  53. 3
  54. 5
  55. 2
  56. 3
  57. 4
  58. 1
  59.  
  60. *//*
  61. 11
  62. 1
  63. 2
  64. 3
  65. 4
  66. 1
  67. 9
  68. 8
  69. 7
  70. 1
  71. 5
  72. 2
  73.  
  74. */
  75.  
  76.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×