fork(3) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int t, n, *li, x, p = 0, k = 0;
  8. char *tab;
  9.  
  10. cin >> t;
  11.  
  12. for (int i = 0; i < t; i++)
  13. {
  14. cin >> n;
  15.  
  16. tab = new char[n - 1];
  17. li = new int[n - 1];
  18.  
  19. getchar();
  20.  
  21. for (int j = 0; j < n - 1; j++)
  22. {
  23. tab[j] = getchar();
  24. li[j] = j + 1;
  25. }
  26. li[n - 1] = n;
  27.  
  28. x = n;
  29.  
  30. while (x != 1)
  31. {
  32.  
  33. for (int a = 0; a < x; a += 2)
  34. {
  35. if (tab[k] == 'A')
  36. {
  37. li[p] = li[a];
  38. }
  39. else
  40. {
  41. li[p] = li[a + 1];
  42. }
  43. k++;
  44. p++;
  45. }
  46. x /= 2;
  47. p = 0;
  48.  
  49. }
  50.  
  51. cout << li[0] << endl;
  52. k = 0;
  53. delete[] tab;
  54. delete[] li;
  55. }
  56.  
  57. return 0;
  58. }
Runtime error #stdin #stdout #stderr 0s 3420KB
stdin
3
8
ABAAABB
16
ABAAAABBAAABABB
32
ABAABBBAAABABABBABAAAAAAAAAABAA
stdout
7
stderr
*** Error in `./prog': free(): invalid next size (fast): 0x08705a20 ***