fork download
  1. #include <algorithm>
  2. #include <iomanip>
  3. #include <iostream>
  4. #include <vector>
  5. #include <set>
  6. #include <numeric>
  7. #include <map>
  8. #include <unordered_map>
  9. #include <stack>
  10. #include <queue>
  11. using namespace std;
  12. #define all(a) a.begin(), a.end()
  13. #define ll long long
  14. #define fo(i,n) for (long long i = 0; i < n; i++)
  15. int main()
  16. {
  17. ll i,a,b,c,n,m,k;
  18. ios_base::sync_with_stdio(false);
  19. string input;
  20. cin.tie(0); cout.tie(0);
  21. cin >> i;
  22. while (i--)
  23. {
  24. cin >> n >> m >> k;
  25. cin >> input;
  26. bool cond = false;
  27. ll temp = 0;
  28. ll cycle = 0;
  29. ll vv = 0;
  30. ll final;
  31. for (char c : input)
  32. {
  33. if (c == 'L')
  34. {
  35. temp--;
  36. m--;
  37. }
  38. else
  39. {
  40. temp++;
  41. m++;
  42. }
  43. vv++;
  44. if (m == 0 && cond == false)
  45. {
  46. cond = true;
  47. final = vv;
  48. }
  49. if (temp == 0 && cycle == 0)
  50. {
  51. cycle = vv;
  52. }
  53. }
  54. if (cond)
  55. {
  56. if (cycle != 0 && k >= final)
  57. {
  58. cout << 1 + ((k-final)/cycle) << '\n';
  59. }
  60. else
  61. {
  62. if (cycle == 0 && k >= final)
  63. {
  64. cout << 1 << '\n';
  65. }
  66. else
  67. {
  68. cout << 0 << '\n';
  69. }
  70. }
  71. }
  72. else
  73. {
  74. cout << 0 << '\n';
  75. }
  76. }
  77. }
Success #stdin #stdout 0s 5292KB
stdin
6
3 2 6
LLR
2 -1 8
RL
4 -2 5
LRRR
5 3 7
LRRLL
1 1 1
L
3 -1 4846549234412827
RLR
stdout
1
4
1
0
1
2423274617206414