Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define sz(x) x.begin(), x.end()
  5.  
  6. typedef long long ll;
  7. typedef vector<int> vi;
  8. typedef pair<int,int> ii;
  9. typedef vector<ii> vii;
  10.  
  11. int main(){
  12.     string s;
  13.     cin >> s;
  14.     int n0 = 0, n1 = 0, n2 = 0, ne = 0, t, mil = 1000000000;
  15.     for(int i = 0; i < s.size(); ++i){
  16.         t = int(s[i] - '0');
  17.         bool bs = t ? 1 : 0;
  18.         ne += !bs;
  19.         t = t%3;
  20.         if(t == 0){
  21.             n0 = (n0*2 + bs) % mil;
  22.             n1 = (n1*2) % mil;
  23.             n2 = (n2*2) % mil;
  24.         } else if(t == 1){
  25.             int t0 = n0, t1 = n1, t2 = n2;
  26.             n1 = (t1 + t0 + 1) % mil;
  27.             n2 = (t2 + t1) % mil;
  28.             n0 = (t0 + t2) % mil;
  29.         } else {
  30.             int t0 = n0, t1 = n1, t2 = n2;
  31.             n2 = (t2 + t0 + 1) % mil;
  32.             n0 = (t0 + t1) % mil;
  33.             n1 = (t1 + t2) % mil;
  34.         }
  35.     }
  36.  
  37.     cout << (n0 + ne) % mil;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement