# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
710916 | 2023-03-16T04:59:40 Z | Nursik | Lucky Numbers (RMI19_lucky) | C++14 | 1 ms | 340 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 340 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 | 212 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Incorrect | 0 ms | 340 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 | 212 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 0 ms | 340 KB | Output is correct |
6 | Correct | 0 ms | 340 KB | Output is correct |
7 | Incorrect | 0 ms | 340 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |