Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
using namespace std; typedef long long ll; const int maxn = 200005; const ll MOD = 1e9 + 7; int n; string s; ll dp[maxn][8]; ll rec(int at, int remainder) { if(at == n and remainder == 0) { return 1; } if(at == n) { return 0; } if(dp[at][remainder] != -1) { return dp[at][remainder]; } ll res = 0; res += rec(at + 1, remainder); res %= MOD; int new_remainder = (remainder * 10 + (s[at] - '0')) % 8; res += rec(at + 1, new_remainder); res %= MOD; dp[at][remainder] = res; return res; } int main() { ios_base::sync_with_stdio(false); cin >> n >> s; memset(dp, -1, sizeof dp); cout << rec(0, 0) - 1 << endl; return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)