fork(6) download
  1. #include<iostream>
  2. #include<fstream>
  3. #include<sstream>
  4. #include<cstdio>
  5. #include<stdlib.h>
  6. #include<string>
  7. #include<cstring>
  8. #include<cmath>
  9. #include<algorithm>
  10. #include<stack>
  11. #include<queue>
  12. #include<vector>
  13. #include<utility>
  14. #include<set>
  15. #include<map>
  16. #include<iomanip>
  17.  
  18. using namespace std;
  19.  
  20. typedef long long ll;
  21. typedef unsigned long long ull;
  22. typedef pair<int,int> pa;
  23. typedef vector<int> vint;
  24. typedef vector<ll> vin;
  25. typedef vector<string> vs;
  26. typedef vector<vector<ll> > vvin;
  27. typedef vector<bool> vb;
  28.  
  29. #define REP(i,a,b) for(ll i=a;i<b;i++)
  30. #define rep(i,n) REP(i,0,n)
  31. #define BREP(i,a,b) for(ll i=a-1;i>=b;i--)
  32. #define brep(i,n) BREP(i,n,0)
  33. #define pb push_back
  34. #define inf 999999999
  35. #define SIZE 10000000
  36. #define mp make_pair
  37. #define sz size()
  38. #define NIL 0
  39. #define DEBUG 0
  40. #define all(vec) (vec).begin(),(vec).end()
  41. #define NEG -1
  42. #define PI 3.14159265359
  43. #define EPS 1e-9
  44.  
  45. int main() {
  46. int k,nsum[1000005],sum[1000005];
  47. ll ret=0;
  48. string str;
  49. cin>>k>>str;
  50. sum[0]=str[0]==1?1:0;
  51. rep(i,str.sz)
  52. nsum[i]=0;
  53. nsum[0]=1;
  54. REP(i,1,str.sz) {
  55. sum[i]=sum[i-1]+str[i]==1;
  56. nsum[sum[i]]++;
  57. }
  58. rep(i,str.sz)
  59. ret+=(sum[i]>=k?nsum[sum[i]-k]:0);
  60. cout<<ret<<"\n";
  61. return 0;
  62. }
Success #stdin #stdout 0s 11176KB
stdin
1
1010
stdout
0