murugappan_s

DIVFOUR - Editorial

Oct 14th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define ld long double
  4. #define pb push_back
  5. #define x first
  6. #define y second
  7. #define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  8. #define PI (atan(1)*4)
  9. #define mp make_pair
  10. using namespace std;
  11.  
  12. //modulo op
  13.  
  14. ll mod = 1e9 + 7;
  15.  
  16. ll add(ll a, ll b) {
  17.     return (a + b) % mod;
  18. }
  19.  
  20. ll sub(ll a, ll b) {
  21.     return ((a - b) % mod + mod) % mod;
  22. }
  23.  
  24. ll mul(ll a, ll b) {
  25.     return (a * b) % mod;
  26. }
  27. //end of modulo op
  28.  
  29. ll dp[10], ans, pow2 = 1;
  30. string s;
  31. int main()
  32. {
  33.     fastread;
  34.     cin >> s;
  35.     for (int i = 0; i < s.size(); i++) {
  36.         int lastdig = s[i] - '0';
  37.         if (lastdig % 4 == 0)
  38.             ans = add(ans, 1);
  39.         for (int j = 0; j < 10; j++) {
  40.             int last2dig = j * 10 + lastdig;
  41.             if (last2dig % 4 == 0)
  42.                 ans = add(ans, dp[j]);
  43.         }
  44.         dp[lastdig] = add(dp[lastdig], pow2);
  45.         pow2 = mul(2, pow2);
  46.     }
  47.     cout << ans;
  48.     return 0;
  49. }
Add Comment
Please, Sign In to add comment