fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class UniformWeights {
  9.  
  10. public static void main(String[] args) {
  11. Scanner in = new Scanner(System.in);
  12. String s = in.next();
  13. int n = in.nextInt();
  14.  
  15. Set<Integer> sumList = new HashSet<>();
  16. char prev = s.charAt(0);
  17. sumList.add(prev - 'a' + 1);
  18. int sum = prev - 'a' + 1;
  19. for (int i = 1; i < s.length(); i++) {
  20. char next = s.charAt(i);
  21. if (next == prev) {
  22. sum += (prev - 'a' +1);
  23. sumList.add(sum);
  24. } else {
  25. sumList.add(next - 'a' + 1);
  26. prev = next;
  27. sum = prev - 'a' + 1;
  28. }
  29. }
  30.  
  31. for (int a0 = 0; a0 < n; a0++) {
  32. int x = in.nextInt();
  33. // your code goes here
  34. if (sumList.contains(x))
  35. System.out.println("Yes");
  36. else
  37. System.out.println("No");
  38. }
  39. }
  40. }
  41.  
Success #stdin #stdout 0.06s 4386816KB
stdin
abccddde
6
1
3
12
5
9
10
stdout
Yes
Yes
Yes
Yes
No
No