Submission #74771944


Source Code Expand

#include <bits/stdc++.h>
using ull = unsigned long long int;
using ll = long long int;
using lll = __int128;
using namespace std;
const int mod = 1e9 + 7;
int d[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
inline string sread() {
    string s;
    char ch = getchar();
    // 跳过空白字符
    while (ch == ' ' || ch == '\n' || ch == '\r') ch = getchar();
    // 读取非空白字符
    while (ch != ' ' && ch != '\n' && ch != '\r' && ch != EOF) {
        s += ch;
        ch = getchar();
    }
    return s;
}
ll read(){
    ll k = 0,f = 1;
    char c = getchar();
    while(c < '0' || c > '9')
    {
        if(c == '-')f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9')k = k * 10 + c - '0',c = getchar();
    return k * f; // 别忘记标记的负数要乘进去
}
// 调用时用 n = in();
void print(ll x){
    if(x < 0)putchar('-'),x = -x;
    if(x < 10)putchar(x + '0');
    else print(x / 10),putchar(x % 10 + '0');
}
// 直接调用 out(n) 就行了
ll ksm(ll base, ll e){
    ll res = 1;
    while(e){
        if(e & 1){
            res = res * base % mod;
        }
        base = base * base % mod;
        e >>= 1;
    }
    return res;
}//ksm板子
vector<vector<ll>> matrix_mul (vector<vector<ll>>& a, vector<vector<ll>>& b) {
    int l1 = a.size(), l2 = b[0].size();
    vector<vector<ll>>res(l1, vector<ll>(l2, 0));
    for(int i = 0; i < l1; i++){
        for(int k = 0; k < a[0].size(); k++){
            if(a[i][k]){
                for(int j = 0; j < l2; j++){
                    res[i][j] = (res[i][j] + a[i][k] * b[k][j]);
                }
            }
        }
    }
    return res;
}// 矩阵a * 矩阵b(矩阵乘法)
void Solve(){
    ll n = read();
    string num = to_string(n);
    int w = num.size();
    ll memo[20][2][2][180][11];
    memset(memo, -1, sizeof(memo));
    auto DP = [&](auto && self, int len, int is_limit, int is0, int sum, int pre) -> ll{
        if(len == w){
            return sum * (is0 + 1);
        }
        if(memo[len][is_limit][is0][sum][pre] != -1){
            return memo[len][is_limit][is0][sum][pre];
        }
        int cur = num[len] - '0';
        ll res = 0;
        if(is_limit){
            if(pre == 10){
                res = (res + self(self, len + 1, 0, 0, 0, 10)) % mod;
                for(int j = 1; j <= cur; j++){
                    res = (res + self(self, len + 1, j == cur, 0, 0, j)) % mod;
                }
            }
            else{
                for(int j = 0; j <= cur; j++){
                    res = (res + self(self, len + 1, j == cur, is0 | (j == 0), sum + abs(j - pre), j)) % mod;
                }
            }
        }
        else{
            if(pre == 10){
                res = (res + self(self, len + 1, 0, 0, 0, 10)) % mod;
                for(int j = 1; j < 10; j++){
                    res = (res + self(self, len + 1, 0, 0, 0, j)) % mod;
                }
            }
            else{
                for(int j = 0; j < 10; j++){
                    res = (res + self(self, len + 1, 0, is0 | (j == 0), sum + abs(pre - j), j)) % mod;
                }
            }
        }
        return memo[len][is_limit][is0][sum][pre] = res;
    };
    cout << DP(DP, 0, 1, 0, 0, 10) << '\n';
}
signed main(){
    int T = 1;
    while(T--){
        Solve();
    }
    return 0;
}

Submission Info

Submission Time
Task E - Hiking Score on a Mountain Trail
User wmxw
Language C++23 (GCC 15.2.0)
Score 466
Code Size 3428 Byte
Status AC
Exec Time 3 ms
Memory 4900 KiB

Compile Error

./Main.cpp: In function 'std::vector<std::vector<long long int> > matrix_mul(std::vector<std::vector<long long int> >&, std::vector<std::vector<long long int> >&)':
./Main.cpp:53:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for(int k = 0; k < a[0].size(); k++){
      |                        ~~^~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 466 / 466
Status
AC × 5
AC × 45
Set Name Test Cases
Sample sample01.txt, sample02.txt, sample03.txt, sample04.txt, sample05.txt
All sample01.txt, sample02.txt, sample03.txt, sample04.txt, sample05.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in40.txt
Case Name Status Exec Time Memory
in01.txt AC 2 ms 4780 KiB
in02.txt AC 2 ms 4768 KiB
in03.txt AC 1 ms 4760 KiB
in04.txt AC 2 ms 4688 KiB
in05.txt AC 2 ms 4688 KiB
in06.txt AC 2 ms 4808 KiB
in07.txt AC 2 ms 4824 KiB
in08.txt AC 2 ms 4824 KiB
in09.txt AC 2 ms 4700 KiB
in10.txt AC 2 ms 4688 KiB
in11.txt AC 2 ms 4824 KiB
in12.txt AC 2 ms 4680 KiB
in13.txt AC 2 ms 4700 KiB
in14.txt AC 2 ms 4820 KiB
in15.txt AC 2 ms 4688 KiB
in16.txt AC 2 ms 4900 KiB
in17.txt AC 2 ms 4832 KiB
in18.txt AC 2 ms 4872 KiB
in19.txt AC 2 ms 4680 KiB
in20.txt AC 2 ms 4900 KiB
in21.txt AC 2 ms 4880 KiB
in22.txt AC 2 ms 4820 KiB
in23.txt AC 1 ms 4772 KiB
in24.txt AC 2 ms 4824 KiB
in25.txt AC 2 ms 4832 KiB
in26.txt AC 2 ms 4688 KiB
in27.txt AC 2 ms 4760 KiB
in28.txt AC 2 ms 4868 KiB
in29.txt AC 2 ms 4872 KiB
in30.txt AC 2 ms 4872 KiB
in31.txt AC 3 ms 4872 KiB
in32.txt AC 2 ms 4820 KiB
in33.txt AC 2 ms 4840 KiB
in34.txt AC 2 ms 4832 KiB
in35.txt AC 2 ms 4816 KiB
in36.txt AC 2 ms 4816 KiB
in37.txt AC 2 ms 4772 KiB
in38.txt AC 2 ms 4688 KiB
in39.txt AC 2 ms 4772 KiB
in40.txt AC 2 ms 4740 KiB
sample01.txt AC 2 ms 4700 KiB
sample02.txt AC 2 ms 4680 KiB
sample03.txt AC 2 ms 4680 KiB
sample04.txt AC 2 ms 4840 KiB
sample05.txt AC 2 ms 4768 KiB