fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, m;
  6. cin >> n >> m;
  7. int a[n+1];
  8. int ans = 0, dem = 0;
  9. map<int, int> p;
  10. for (int i = 1; i <= n; i++) {
  11. string b;
  12. cin >> b;
  13. a[i]= b.size();
  14. dem++;
  15. if (dem > m+1) {
  16. p[a[i-m-1]]--;
  17. dem--;
  18. }
  19.  
  20. ans -= (p[a[i]] * (p[a[i]] - 1)) / 2;
  21. p[a[i]]++;
  22. ans += (p[a[i]] * (p[a[i]] - 1)) / 2;
  23. }
  24. cout << ans << endl;
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
0