This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |