結果

問題 No.319 happy b1rthday 2 me
ユーザー mamekinmamekin
提出日時 2015-12-20 01:33:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,752 bytes
コンパイル時間 1,384 ms
コンパイル使用メモリ 91,964 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 13:10:37
合計ジャッジ時間 1,860 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

long long solve(long long n)
{
    if(n < 2)
        return 0;

    long long mod = 1000000000000;
    vector<long long> dp(4, 0);
    dp[0] = 1;

    long long ans = 1;
    while(mod > 0){
        if(n / mod > 2)
            ans += mod / 10;
        else if(n / mod == 2)
            ans += (n % mod + 8) / 10;

        int curr = n / mod % 10;
        vector<long long> nextDp(4, 0);
        for(int i=0; i<4; ++i){
            if(dp[i] == 0)
                continue;

            for(int a=0; a<=9; ++a){
                if(!(i & 1) && curr < a)
                    continue;
                if((i & 2) && a == 2){
                    if((i & 1) || a < curr)
                        ans += dp[i] * mod;
                    else
                        ans += (dp[i] - 1) * mod + n % mod + 1;
                }

                int k = i & 1;
                if(a < curr)
                    k |= 1;
                if(a == 1)
                    k |= 2;
                nextDp[k] += dp[i];
            }
        }

        dp.swap(nextDp);
        mod /= 10;
    }

    return ans;
}

int main()
{
    long long a, b;
    cin >> a >> b;

    long long ans = solve(b) - solve(a-1);
    if((a - 1) % 10 == 1){
        long long x = a;
        while(x >= 10)
            x /= 10;
        if(x == 2)
            -- ans;
    }
    cout << ans << endl;

    return 0;
}
0