fork(7) download
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5. typedef long long ll;
  6. const int MAXS = 200010;
  7.  
  8. string A, B;
  9. int F[MAXS][2];
  10.  
  11. int main() {
  12. ios_base::sync_with_stdio(0);
  13. cin.tie(NULL);
  14. cin >> A >> B;
  15. for (int i = 1; i <= B.size(); i++) {
  16. for (int j = 0; j < 2; j++) {
  17. F[i][j] = F[i - 1][j];
  18. }
  19. ++F[i][B[i - 1] - '0'];
  20. }
  21. ll res = 0;
  22. for (int i = 0, c; i < A.size(); i++) {
  23. c = A[i]-'0';
  24. for (int j = 0; j < 2; j++) {
  25. res += abs(c - j) * (F[B.size() - A.size() + i + 1][j] - F[i][j]);
  26. }
  27. }
  28. cout << res << '\n';
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 4968KB
stdin
01
00111
stdout
3