fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  5. #define ll long long
  6. #define rep(i, a, b) for (int i = (a); i < (b); ++i)
  7. #define repr(i, a, b) for (int i = (a); i > (b); --i)
  8. void solve() {
  9. string s; cin>>s;
  10. ll diff; cin>>diff;
  11. ll n = s.size();
  12. ll g = 0;
  13. ll pf[n];
  14. rep(i,0,n){
  15. if(s[i]=='0'){
  16. g++;
  17. }else{
  18. g--;
  19. }
  20. pf[i] = g;
  21. }
  22. ll d = pf[n-1];
  23. ll ans = 0;
  24. rep(i,0,n)
  25. {
  26. if(d == 0 && diff == pf[i])
  27. {
  28. cout << -1 <<endl;
  29. return;
  30. }else{
  31. if((diff-pf[i])%d==0 && (diff-pf[i])/d >=0){
  32. ans++;
  33. }
  34. }
  35. }
  36. cout << ans <<endl;
  37. }
  38.  
  39.  
  40. int main() {
  41. fastio;
  42. solve();
  43. return 0;
  44. }
Success #stdin #stdout 0.01s 5288KB
stdin
10100
2
stdout
5