fork(1) download
  1. import java.io.*;
  2. import java.util.Locale;
  3. import java.util.StringTokenizer;
  4.  
  5. public class TaskB {
  6. private final InputReader reader;
  7. private final OutputWriter writer;
  8.  
  9. public TaskB(InputReader reader, OutputWriter writer) {
  10. this.reader = reader;
  11. this.writer = writer;
  12. }
  13.  
  14. public static void main(String[] args) {
  15. InputReader reader = new InputReader(System.in);
  16. OutputWriter writer = new OutputWriter(System.out);
  17. new TaskB(reader, writer).run();
  18. writer.writer.flush();
  19. }
  20.  
  21. public void run() {
  22. int n = reader.nextInt();
  23. int m = reader.nextInt();
  24. char[] S = reader.next().toCharArray();
  25. int k = S.length;
  26. int[] P = new int[k + 1];
  27. P[0] = P[1] = 0;
  28. for (int i = 2; i <= k; i++) {
  29. P[i] = 0;
  30. for (int p = P[i - 1]; p != 0; p = P[p])
  31. if (S[p] == S[i - 1]) {
  32. P[i] = p + 1;
  33. break;
  34. }
  35. if (P[i] == 0 && S[i - 1] == S[0])
  36. P[i] = 1;
  37. }
  38. boolean[] good = new boolean[k + 1];
  39. good[0] = true;
  40. for (int p = k; p != 0; p = P[p])
  41. good[p] = true;
  42. int end = 0;
  43. int ans = 1;
  44. final int MOD = 1000 * 1000 * 1000 + 7;
  45. for (int i = 0; i < m; i++) {
  46. int x = reader.nextInt();
  47. if (x > end) {
  48. for (int j = 0; j < x - end - 1; j++)
  49. ans = (int)((ans * 1l * 26) % MOD);
  50. } else {
  51. if (!good[end - x + 1])
  52. ans = 0;
  53. }
  54. end = x + k - 1;
  55. }
  56. while (end < n) {
  57. ans = (int) ((ans * 1l * 26) % MOD);
  58. end++;
  59. }
  60. writer.printf("%d\n", ans);
  61. }
  62.  
  63.  
  64. static class InputReader {
  65. public BufferedReader reader;
  66. public StringTokenizer tokenizer;
  67.  
  68. public InputReader(InputStream stream) {
  69. reader = new BufferedReader(new InputStreamReader(stream), 32768);
  70. tokenizer = null;
  71. }
  72.  
  73. public String next() {
  74. while (tokenizer == null || !tokenizer.hasMoreTokens()) {
  75. try {
  76. tokenizer = new StringTokenizer(reader.readLine());
  77. } catch (IOException e) {
  78. throw new RuntimeException(e);
  79. }
  80. }
  81. return tokenizer.nextToken();
  82. }
  83.  
  84. public int nextInt() {
  85. return Integer.parseInt(next());
  86. }
  87.  
  88. public double nextDouble() {
  89. return Double.parseDouble(next());
  90. }
  91.  
  92. public long nextLong() {
  93. return Long.parseLong(next());
  94. }
  95. }
  96.  
  97. static class OutputWriter {
  98. public PrintWriter writer;
  99.  
  100. OutputWriter(OutputStream stream) {
  101. writer = new PrintWriter(stream);
  102. }
  103.  
  104. public void printf(String format, Object... args) {
  105. writer.print(String.format(Locale.ENGLISH, format, args));
  106. }
  107. }
  108. }
  109.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:5: error: class TaskB is public, should be declared in a file named TaskB.java
public class TaskB {
       ^
1 error
stdout
Standard output is empty