답안 #492781

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
492781 2021-12-08T21:48:11 Z maksim1744 Lucky Numbers (RMI19_lucky) C++17
14 / 100
1 ms 460 KB
#include "bits/stdc++.h"
using namespace std;
 
using ll = long long;
 
#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()
 
const int N = 30, mod = 1e9 + 7;
ll dp[N][10][2];
 
ll calc(string s){
    assert(s[0] != '0');
    int n = sz(s);
    forn(i, N)forn(j, 10)forn(k, 2)dp[i][j][k] = 0;
    for(int d = 1;d <= s[0] - '0'; ++d){
        dp[0][d][(int)(d < (s[0] - '0'))] = 1;
    }   
    for(int i = 1;i < n; ++i){
        for(int lst = 0; lst <= 9; ++lst){
            for(int cur = 0;cur <= 9; ++cur){
                if(lst == 1 && cur == 3)continue;
                if(cur < (s[i] - '0')){
                    dp[i][cur][1] += (dp[i - 1][lst][0] + dp[i - 1][lst][1]) % mod;
                    dp[i][cur][1] %= mod;
 
                }else if(cur == (s[i] - '0')){
                    dp[i][cur][1] += dp[i - 1][lst][1];
                    dp[i][cur][1] %= mod;
 
                    dp[i][cur][0] += dp[i - 1][lst][0];
                    dp[i][cur][0] %= mod; 
                }else{
                    dp[i][cur][1] += dp[i - 1][lst][1];
                    dp[i][cur][1] %= mod;
                }
            }
        }
    }
 
    ll ans = 0;
    for(int i = 0;i <= 9; ++i){
        ans += (dp[n - 1][i][0] + dp[n - 1][i][1]) % mod;
        ans %= mod;
    }
    return ans;
}
 
ll cnt(string s){
    // return calc(s);
    // if(s == "0")return 1;
    ll ans = calc(s);
 
    string a = "9";
    while(sz(a) < sz(s)){
        ans += calc(a);
        ans %= mod;
        a += "9";
    }
 
    return (ans + 1) % mod;
}
 
void solve()
{
    int n, q;
    string s;
    cin >> n >> q >> s;
    assert(s.size() == n);
    assert(q == 0);
    if (s == "0") {
        cout << 1 << '\n';
    } else {
        cout << cnt(s) % mod << "\n";
    }
}   
 
int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from lucky.cpp:1:
lucky.cpp: In function 'void solve()':
lucky.cpp:73:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   73 |     assert(s.size() == n);
      |            ~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Runtime error 1 ms 460 KB Execution killed with signal 6
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Runtime error 1 ms 460 KB Execution killed with signal 6
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Runtime error 1 ms 460 KB Execution killed with signal 6