Advertisement
porosh45

UVa 11536

Dec 13th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t;
  6. cin>>t;
  7. for(int j = 1;j<=t;j++)
  8. {
  9. int n , m , k;
  10. cin>>n>>m>>k;
  11. int a[n+1],Rp = 1,Lp = 1,ans = 0, c = 0 ,pos;
  12. a[1]=1;a[2]=2;a[3]=3;
  13. for(int i = 4;i<=n;i++)
  14. a[i]= ((a[i-1]+a[i-2]+a[i-3])%m)+1;
  15.  
  16. map<int , int> check;
  17. while(Rp<=n)
  18. {
  19. //cout<<"first while loop "<<endl;
  20. if(a[Rp]<=k)
  21. {
  22. check[a[Rp]]++;
  23. if(check.size()==k)
  24. c=1;
  25. }
  26. if(c)
  27. {
  28. ans = Rp - Lp +1;
  29. int Size = check.size();
  30. while(Size==k)
  31. {//problem ei loop e hoitese...map er size change hoitese still loop ghurtese...bujhtesi na kn...onkk print koira dekhsi kaj hoy na..
  32. if(a[Lp]<=k)
  33. {
  34. pos = Rp - Lp + 1;
  35. if((check[a[Lp]]-1) == 0)
  36. {
  37. check.erase(a[Lp]);
  38. c=0;
  39. Size = check.size();
  40. }
  41. check[a[Lp]]--;
  42. }
  43. Lp++;
  44. }
  45. if(pos<ans)
  46. ans = pos;
  47. }
  48. Rp++;
  49. }
  50. if(ans>=k)
  51. cout<<"Case "<<j<<": "<<ans<<endl;
  52. else
  53. cout<<"Case "<<j<<": sequence nai"<<endl;
  54. check.clear();
  55. memset(a,0,(n+1)*sizeof(a[0]));
  56. }
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement