# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
710916 | Nursik | Lucky Numbers (RMI19_lucky) | C++14 | 1 ms | 340 KiB |
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 <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <bitset>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ld long double
const ll maxn = 5e3 + 1, maxm = 80;
const ll mod = 1e9 + 7, inf = 1e9;
const ld eps = 1e-9;
int n, q;
string s;
int dig[maxn];
ll dp[maxn][10][2];
int calc(string x){
x = '#' + x;
int m = (int)x.size();
for (int j = 1; j < m; ++j){
dig[j] = x[j] - '0';
}
for (int i = 0; i <= dig[1]; ++i){
int ni = 1, nj = i, nk = (i == dig[1]);
dp[ni][nj][nk] = 1;
}
for (int i = 2; i < m; ++i){
for (int j = 0; j < 10; ++j){
for (int k = 0; k < 2; ++k){
if (dp[i - 1][j][k] > 0){
for (int ndig = 0; ndig < 10; ++ndig){
int ni = i, nj = ndig, nk = k;
if (k == 0){
if (!(ndig == 3 && j == 1)){
dp[ni][ndig][nk] = (dp[ni][ndig][nk] + dp[i - 1][j][k]) % mod;
}
}
else{
if (ndig < dig[i]){
nk = 0;
if (!(ndig == 3 && j == 1)){
dp[ni][ndig][nk] = (dp[ni][ndig][nk] + dp[i - 1][j][k]) % mod;
}
}
nk = k;
if (ndig == dig[i]){
if (!(ndig == 3 && j == 1)){
dp[ni][ndig][nk] = (dp[ni][ndig][nk] + dp[i - 1][j][k]) % mod;
}
}
}
}
}
}
}
}
ll ans = 0;
for (int i = 0; i <= 9; ++i){
for (int j = 0; j < 2; ++j){
ans = (ans + dp[m - 1][i][j]) % mod;
// cout << i << " " << j << " " << dp[m - 1][i][j] << '\n';
}
}
return ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
cin >> s;
if (q == 0){
cout << calc(s) << '\n';
exit(0);
}
}
Compilation message (stderr)
# | 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... |