Submission #1540362


Source Code Expand

public class Main {
  private static void solve() {
    char[] a = ns();
    int n = a.length;

    int[][] sum = new int[26][n + 1];

    for (int i = 1; i <= n; i++) {
      int c = a[i - 1] - 'a';
      for (int j = 0; j < 26; j++) {
        if (c == j) {
          sum[j][i] = sum[j][i - 1] + 1;
        } else {
          sum[j][i] = sum[j][i - 1];
        }
      }
    }

    long count = 0;
    for (int i = 0; i < n; i++) {
      int c = a[i] - 'a';
      count += (n - i) - (sum[c][n] - sum[c][i]);
    }
    out.println(count + 1);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = System.getProperty("debug");
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Submission Info

Submission Time
Task B - Reverse and Compare
User hiromi_ayase
Language Java8 (OpenJDK 1.8.0)
Score 500
Code Size 3006 Byte
Status AC
Exec Time 139 ms
Memory 52052 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 23
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt
Case Name Status Exec Time Memory
sample_01.txt AC 70 ms 15828 KB
sample_02.txt AC 71 ms 19156 KB
sample_03.txt AC 70 ms 21204 KB
subtask_1_01.txt AC 70 ms 16912 KB
subtask_1_02.txt AC 136 ms 48852 KB
subtask_1_03.txt AC 68 ms 20436 KB
subtask_1_04.txt AC 69 ms 19924 KB
subtask_1_05.txt AC 110 ms 21204 KB
subtask_1_06.txt AC 71 ms 18388 KB
subtask_1_07.txt AC 84 ms 21968 KB
subtask_1_08.txt AC 139 ms 51984 KB
subtask_1_09.txt AC 138 ms 52052 KB
subtask_1_10.txt AC 133 ms 48084 KB
subtask_1_11.txt AC 136 ms 49108 KB
subtask_1_12.txt AC 133 ms 51924 KB
subtask_1_13.txt AC 133 ms 50132 KB
subtask_1_14.txt AC 131 ms 48376 KB
subtask_1_15.txt AC 135 ms 50004 KB
subtask_1_16.txt AC 134 ms 50004 KB
subtask_1_17.txt AC 134 ms 49108 KB