提出 #61384983


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,b) for(int i=0;i<b;i++)
#define all(a) (a).begin(),(a).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#define inf (ll)2e+18
#define INF (int)2e9
using P = pair<int,int>;
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;

int main(){
    ll l,r; cin>>l>>r;
    auto f = [&](ll x) -> ll {
        string s = to_string(x);
        int n = s.size();
        vector dp(n+1,vector(2,vector<ll>(10)));
        dp[0][0][0] = 1;
        rep(i,n)rep(j,2)rep(k,10){
            int lim = j? 9: s[i]-'0';
            rep(x,lim+1){
                if(k){
                    if(x >= k) continue;
                    dp[i+1][j||x<lim][k] += dp[i][j][k];
                } else {
                    dp[i+1][j||x<lim][x] += dp[i][j][k];
                }
            }
        }
        ll ret = 0;
        rep(j,2)rep(k,10) ret += dp[n][j][k];
        return ret;
    };
    ll ans = f(r) - f(l-1);
    cout<<ans<<endl;
    return 0;
}

提出情報

提出日時
問題 C - Snake Numbers
ユーザ kero3755
言語 C++ 23 (gcc 12.2)
得点 350
コード長 1242 Byte
結果 AC
実行時間 1 ms
メモリ 3704 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 350 / 350
結果
AC × 3
AC × 29
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 03_random3_04.txt, 04_handmade_00.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt, 04_handmade_05.txt, 04_handmade_06.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3500 KiB
00_sample_01.txt AC 1 ms 3412 KiB
00_sample_02.txt AC 1 ms 3612 KiB
01_random_00.txt AC 1 ms 3508 KiB
01_random_01.txt AC 1 ms 3540 KiB
01_random_02.txt AC 1 ms 3412 KiB
01_random_03.txt AC 1 ms 3508 KiB
01_random_04.txt AC 1 ms 3520 KiB
01_random_05.txt AC 1 ms 3612 KiB
01_random_06.txt AC 1 ms 3516 KiB
01_random_07.txt AC 1 ms 3704 KiB
01_random_08.txt AC 1 ms 3508 KiB
01_random_09.txt AC 1 ms 3480 KiB
02_random2_00.txt AC 1 ms 3504 KiB
02_random2_01.txt AC 1 ms 3520 KiB
02_random2_02.txt AC 1 ms 3540 KiB
02_random2_03.txt AC 1 ms 3516 KiB
03_random3_00.txt AC 1 ms 3504 KiB
03_random3_01.txt AC 1 ms 3508 KiB
03_random3_02.txt AC 1 ms 3516 KiB
03_random3_03.txt AC 1 ms 3476 KiB
03_random3_04.txt AC 1 ms 3620 KiB
04_handmade_00.txt AC 1 ms 3568 KiB
04_handmade_01.txt AC 1 ms 3580 KiB
04_handmade_02.txt AC 1 ms 3512 KiB
04_handmade_03.txt AC 1 ms 3504 KiB
04_handmade_04.txt AC 1 ms 3516 KiB
04_handmade_05.txt AC 1 ms 3508 KiB
04_handmade_06.txt AC 1 ms 3608 KiB