Advertisement
a53

reactii

a53
Feb 20th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <cstdio>
  2. #define NMax 15024
  3. using namespace std;
  4. typedef struct {int lo,hi;} interval;
  5. int N,T,k;
  6. interval st[NMax];
  7.  
  8. // returneaza 1 daca si numai daca ultimele
  9. // doua intervale din stiva pot fi unite, caz in care le si uneste
  10. int uneste()
  11. {
  12. if(st[k-1].hi+1==st[k].lo)
  13. {
  14. st[k-1].hi=st[k].hi;
  15. --k;
  16. return 1;
  17. }
  18. else
  19. if(st[k].hi+1==st[k-1].lo)
  20. {
  21. st[k-1].lo=st[k].lo;
  22. --k;
  23. return 1;
  24. }
  25. return 0;
  26. }
  27.  
  28. int main()
  29. {
  30. int i,x;
  31. freopen("reactii.in","r",stdin);
  32. freopen("reactii.out","w",stdout);
  33. scanf("%d %d",&N,&T);
  34. for (;T;--T)
  35. {
  36. k=0;
  37. for(i=1;i<=N;++i)
  38. {
  39. scanf("%d",&x);
  40. ++k;st[k].lo=x;st[k].hi=x;
  41. for(;k>1&&uneste(););
  42. }
  43. printf("%d\n",(k==1));
  44. }
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement