fork 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 Ideone
  9. {
  10. public static List<Integer> sol(String[]s){
  11. int n=s.length;
  12. List<Integer>res=new ArrayList<>(n);
  13. for(int i=0;i<n;i++){
  14. res.add(0);
  15. }
  16. int g[][]=new int[200005][26];
  17. for(int i=n-1;i>=0;i--){
  18. String u=s[i];
  19. int count=0;
  20. for(int j=0;j<u.length();j++){
  21. char c=s[i].charAt(j);
  22. count=count+g[j][c-'a'];
  23. g[j][c-'a']++;
  24. }
  25. res.set(i,count);
  26. }
  27. return res;
  28. }
  29. public static void main (String[] args) throws java.lang.Exception
  30. {
  31. // your code goes here
  32. Scanner sc=new Scanner(System.in);
  33. int n=sc.nextInt();
  34. String s[]=new String[n];
  35. for(int i=0;i<n;i++){
  36. s[i]=sc.next();
  37. }
  38. List<Integer>res=sol(s);
  39. System.out.println(res);
  40. }
  41. }
Success #stdin #stdout 0.15s 81104KB
stdin
3
abc
dea
bac
stdout
[1, 0, 0]