fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin>>n;
  7. vector<string> array(n);
  8. for(int i=0;i<n;i++)
  9. cin>>array[i];
  10. vector<vector<int>> g(200000 + 5, vector<int>(28, 0));
  11. vector<int> answer(n, 0);
  12. for(int i=n-1;i>=0;i--){
  13. string s = array[i];
  14. // int col=0;
  15. int cnt=0;
  16. for(int j=0;j<s.size();j++){
  17. int val=int(s[j])-97;
  18. cnt=cnt+g[val][j];
  19. g[val][j]=g[val][j]+1;
  20. }
  21. answer[i]=cnt;
  22. }
  23. for(int i=0;i<answer.size();i++)
  24. {
  25. cout<<answer[i]<<" ";
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0.02s 30100KB
stdin
3
abc ade bbc
stdout
3 0 0