結果

問題 No.319 happy b1rthday 2 me
ユーザー nebukuro09nebukuro09
提出日時 2017-03-10 15:49:59
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 1,949 bytes
コンパイル時間 958 ms
コンパイル使用メモリ 105,072 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-03 02:03:53
合計ジャッジ時間 2,096 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

long solve_one(string n) {
    int m = n.length.to!int;
    auto dp = new long[][][][](m+1, 2, 2, 7); // 桁, n未満か, 前の数字が1か, これまで何個の12があったか
    dp[0][0][0][0] = 1;

    foreach (i; 0..m) {
        foreach (j; 0..2) {
            foreach (k; 0..2) {
                foreach (l; 0..6) {
                    int digit = j ? 10 : (n[i]-'0'+1);
                    foreach (d; 0..digit) {
                        dp[i+1][j|(d<n[i]-'0')][d==1][l+(k==1&&d==2)] += dp[i][j][k][l];
                    }
                }
            }
        }
    }

    long ret = 0;
    foreach (k; 0..2) {
        foreach (l; 1..7) {
            ret += (dp[m][1][k][l]) * l;
        }
    }
    return ret;
}

long solve_two(string n) {
    int m = n.length.to!int;
    auto dp = new long[][][][](m+1, 2, 10, 2); // 桁, n未満か, 最初の桁の数字, 最後の桁が1か
    dp[0][0][0][0] = 1;

    foreach (i; 0..m) {
        foreach (j; 0..2) {
            foreach (k; 0..10) {
                foreach (l; 0..2) {
                    int digit = j ? 10 : (n[i]-'0'+1);
                    foreach (d; 0..digit) {
                        int first = (k == 0 && d != 0) ? d : k;
                        dp[i+1][j|(d<n[i]-'0')][first][i==m-1&&d==1] += dp[i][j][k][l];
                    }
                }
            }
        }
    }

    return dp[m][1][2][1];
    
}


void main() {
    auto s = readln.split;
    auto a = s[0].to!long;
    auto b = s[1].to!long;
    long ans;
    ans =  solve_one((b+1).to!string) - solve_one(s[0]);
    ans += max(0, solve_two((b).to!string) - solve_two((a+1).to!string));
    if (a == 1 && b > 1) ans += 1;
    //if (s[1][0] == '2' && s[1][$-1] == '1') ans -= 1;
    ans.writeln;
}
0