fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const long long MOD = 1e9 + 7;
  5.  
  6. int main() {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9.  
  10. string s;
  11. cin >> s;
  12.  
  13. // digit dp: less = already < L, tight = still == L
  14. long long less = 0, tight = 1;
  15.  
  16. for (char c : s) {
  17. int bit = c - '0';
  18.  
  19. if (bit == 0) {
  20. // must choose (0,0) to stay tight, else goes invalid
  21. less = (less * 3) % MOD; // (0,0), (0,1), (1,0)
  22. } else {
  23. // bit == 1
  24. long long new_less = (less * 3 + tight) % MOD; // tight picks (0,0) -> less
  25. long long new_tight = (tight * 2) % MOD; // (0,1) or (1,0)
  26. less = new_less;
  27. tight = new_tight;
  28. }
  29. }
  30.  
  31. cout << (less + tight) % MOD << "\n";
  32. return 0;
  33. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
1