fork download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4.  
  5. void solve() {
  6. int n,x,k;
  7. cin >> n>>x>>k;
  8. string s;
  9. cin>>s;
  10. int cnt=0;
  11. for(int i=0;i<n;i++){
  12. if(x==0){
  13. cnt++;
  14. break;
  15. }
  16. if(s[i]=='L'){
  17. k--;
  18. x--;
  19. }
  20. else if(s[i]=='R'){
  21. k--;
  22. x++;
  23. }
  24. }
  25. if(x==0){
  26. cnt++;
  27. }
  28. if(cnt==0){
  29. cout<<0<<endl;
  30. return;
  31. }
  32. int cnt2=0;
  33. int time=1;
  34. if(s[0]=='L'){
  35. x--;
  36. }
  37. else if(s[0]=='R'){
  38. x++;
  39. }
  40. for(int i=1;i<n;i++){
  41. if(x==0){
  42. cnt2++;
  43. break;
  44. }
  45. if(s[i]=='L'){
  46. x--;
  47. }
  48. else if(s[i]=='R'){
  49. x++;
  50. }
  51. time++;
  52. }
  53. if(x==0){
  54. cnt2++;
  55. }
  56. if(cnt2==0){
  57. cout<<1<<endl;
  58. return;
  59. }
  60. cnt=1+(k/time);
  61. cout<<cnt<<endl;
  62.  
  63.  
  64. }
  65.  
  66. signed main() {
  67. int t;
  68. cin >> t;
  69. while (t--) {
  70. solve();
  71. }
  72. return 0;
  73. }
  74.  
Success #stdin #stdout 0s 5288KB
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