結果
問題 | No.319 happy b1rthday 2 me |
ユーザー |
|
提出日時 | 2017-03-10 15:49:59 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,949 bytes |
コンパイル時間 | 806 ms |
コンパイル使用メモリ | 114,256 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-12 07:17:33 |
合計ジャッジ時間 | 1,903 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 WA * 10 |
ソースコード
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;}