結果

問題 No.319 happy b1rthday 2 me
ユーザー h_nosonh_noson
提出日時 2016-04-14 13:41:17
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,654 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 63,364 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 01:23:42
合計ジャッジ時間 1,657 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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 ret = 0;
    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);
        }
    }
    ret = dp[0][2][a.size()] + dp[1][2][a.size()];
    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[0] == '2') {
        int n = 0;
        REP (i,1,a.size()-1)
            n = n * 10 + a[i] - '0';
        if (a.back() >= '2')
            n++;
        ret += n;
    }
    return ret;
}

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