結果

問題 No.319 happy b1rthday 2 me
ユーザー h_nosonh_noson
提出日時 2016-04-14 13:57:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,786 bytes
コンパイル時間 539 ms
コンパイル使用メモリ 62,708 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 01:24:15
合計ジャッジ時間 1,346 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 100000000

typedef long long ll;

ll power(ll x, ll n) {
    return n == 0 ? 1 : x * power(x,n-1);
}

ll count(string a) {
    int i, j;
    ll dp[2][3][14] {};
    dp[0][0][0] = 1;
    rep (i,a.size()) {
        int n = a[i] - '0';
        rep (j,10) {
            if (j == 2) {
                dp[0][2][i+1] += n == j ? dp[0][1][i] : 0;
                dp[1][2][i+1] += dp[1][1][i] + (j < n ? dp[0][1][i] : 0);
            }
            else if (j == 1) {
                dp[0][1][i+1] += n == j ? dp[0][0][i] : 0;
                dp[1][1][i+1] += dp[1][0][i] + (j < n ? dp[0][0][i] : 0);
            }
            dp[0][0][i+1] += n == j ? dp[0][0][i] : 0;
            dp[1][0][i+1] += dp[1][0][i] + (j < n ? dp[0][0][i] : 0);
            dp[0][2][i+1] += n == j ? dp[0][2][i] : 0;
            dp[1][2][i+1] += dp[1][2][i] + (j < n ? dp[0][2][i] : 0);
        }
    }
    return dp[0][2][a.size()] + dp[1][2][a.size()];
}

ll count2(string a) {
    int i;
    ll ret = 0;
    rep (i,(int)a.size()-2)
        ret += power(10,i);
    if (a.size() > 1 && a[0] > '2')
        ret += power(10,a.size()-2);
    else if (a.size() > 1 && a[0] == '2') {
        ll n = 0;
        REP (i,1,a.size()-1)
            n = n * 10 + a[i] - '0';
        if (a.back() >= '2')
            n++;
        ret += n;
    }
    if (a.size() > 1 || a[0] >= '2')
        ret++;
    return ret;
    
}

int main() {
    ll num;
    string b;
    cin >> num >> b;
    cout << count(b) + count2(b) - count(to_string(num-1)) - count2(to_string(num)) << endl;
    return 0;
}
0