結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 2 ms
4,380 KB
testcase_30 WA -
testcase_31 AC 2 ms
4,504 KB
testcase_32 AC 2 ms
4,384 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 += solve_two((b+1).to!string) - solve_two(s[0]);
    if (a == 1) ans += 1;
    ans.writeln;
}
0