fork download
  1. import java.util.*;
  2. class Main
  3. {
  4. public static void main(String[]args)
  5. {
  6. Scanner s=new Scanner(System.in);
  7. int t=s.nextInt();
  8. while(t-->0)
  9. {
  10. int n=s.nextInt();
  11. int x=s.nextInt();
  12. String S=s.next();
  13. List<Integer>visited=new ArrayList<>();
  14. int position =x;
  15. visited.add(position);
  16. for(int i=0;i<n;i++)
  17. {
  18. char c=S.charAt(i);
  19. if(c=='L')
  20. {
  21. position--;
  22. }
  23. else
  24. {
  25. position++;
  26. }
  27. if(!visited.contains(position))
  28. {
  29. visited.add(position);
  30. }
  31. }
  32. System.out.println(visited.size());
  33.  
  34. }
  35.  
  36. }
  37. }
Success #stdin #stdout 0.18s 54516KB
stdin
2
6 10
RRLLLL
2 0
LL
stdout
5
3