#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pairll;
typedef pair<ll,ull>pairull;
typedef pair<ll,pairll>pair3l;
typedef long double ld;
#define fr first
#define sc second
#define pb push_back
#define endl '\n'
#define N 100007
#define MOD 1000000007
#define INF 100000000000007
#define eps 0.00000000001
//#define A ll(1e12)
ll n,m,d[N],t[N][2][2];
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
char c;
cin>>c;
d[i]=ll(c-'0');
}
t[0][0][0]=1;
for(int i=1;i<=n;i++){
if(d[i-1]==1 && d[i]==3){
t[i][0][0]=0;
}else if(d[i]==1){
t[i][1][0]=t[i-1][1][0]+t[i-1][0][0];
}else t[i][0][0]=t[i-1][0][0]+t[i-1][1][0];
t[i][1][0]%=MOD;
for(int j=0;j<d[i];j++){
if(j==1){
t[i][1][1]+=t[i-1][1][0]+t[i-1][0][0]+t[i-1][0][1]+t[i-1][1][1];
t[i][1][1]%=MOD;
}else if(j==3){
t[i][0][1]+=t[i-1][0][0]+t[i-1][0][1];
t[i][0][1]%=MOD;
}else{
t[i][0][1]+=t[i-1][1][0]+t[i-1][0][0]+t[i-1][0][1]+t[i-1][1][1];
t[i][0][1]%=MOD;
}
}
for(int j=d[i];j<=9;j++){
if(j==1){
t[i][1][1]+=t[i-1][0][1]+t[i-1][1][1];
t[i][1][1]%=MOD;
}else if(j==3){
t[i][0][1]+=t[i-1][0][1];
t[i][0][1]%=MOD;
}else{
t[i][0][1]+=t[i-1][0][1]+t[i-1][1][1];
t[i][0][1]%=MOD;
}
}
// cout<<(t[i][0][0]+t[i][1][0]+t[i][1][1]+t[i][0][1])%MOD<<" "<<t[i][0][0]<<" "<<t[i][1][0]<<" "<<t[i][0][1]<<" "<<t[i][1][1]<<endl;
}
cout<<(t[n][0][0]+t[n][1][0]+t[n][1][1]+t[n][0][1])%MOD<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |