結果

問題 No.260 世界のなんとか3
ユーザー Lepton_sLepton_s
提出日時 2015-07-31 23:17:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 1,602 bytes
コンパイル時間 790 ms
コンパイル使用メモリ 85,472 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-04-25 07:40:13
合計ジャッジ時間 4,062 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
11,776 KB
testcase_01 AC 8 ms
11,776 KB
testcase_02 AC 9 ms
11,648 KB
testcase_03 AC 176 ms
11,776 KB
testcase_04 AC 173 ms
11,776 KB
testcase_05 AC 39 ms
11,648 KB
testcase_06 AC 29 ms
11,776 KB
testcase_07 AC 120 ms
11,776 KB
testcase_08 AC 89 ms
11,776 KB
testcase_09 AC 54 ms
11,776 KB
testcase_10 AC 136 ms
11,648 KB
testcase_11 AC 126 ms
11,776 KB
testcase_12 AC 81 ms
11,776 KB
testcase_13 AC 29 ms
11,776 KB
testcase_14 AC 114 ms
11,776 KB
testcase_15 AC 38 ms
11,648 KB
testcase_16 AC 101 ms
11,776 KB
testcase_17 AC 82 ms
11,776 KB
testcase_18 AC 82 ms
11,776 KB
testcase_19 AC 104 ms
11,776 KB
testcase_20 AC 76 ms
11,776 KB
testcase_21 AC 67 ms
11,776 KB
testcase_22 AC 114 ms
11,776 KB
testcase_23 AC 19 ms
11,776 KB
testcase_24 AC 90 ms
11,648 KB
testcase_25 AC 113 ms
11,776 KB
testcase_26 AC 72 ms
11,776 KB
testcase_27 AC 8 ms
11,648 KB
testcase_28 AC 177 ms
11,776 KB
testcase_29 AC 219 ms
11,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<25;
typedef pair<int,int> P;
typedef long long ll;
typedef unsigned long long ull;
#define N 11000
ll dp[N][2][3][8][2];
ll mod = 1000000007;

ll calc(string &s){
	int n = s.size();
	memset(dp, 0, sizeof(dp));
	dp[0][0][0][0][0] = 1;
	for(int i = 0; i < n; i++){
		int t = s[i]-'0';
		for(int j = 0; j < 10; j++){
			for(int k = 0; k < 2; k++){
				for(int l = 0; l < 3; l++){
					for(int m = 0; m < 8; m++){
						(dp[i+1][k|(j==3)][(l+j)%3][(m*2+j)%8][1]+=dp[i][k][l][m][1])%=mod;
						if(j<t){
							(dp[i+1][k|(j==3)][(l+j)%3][(m*2+j)%8][1]+=dp[i][k][l][m][0])%=mod;
						} else{
							if(j==t){
								(dp[i+1][k|(j==3)][(l+j)%3][(m*2+j)%8][0]+=dp[i][k][l][m][0])%=mod;
							} 
						}
					}
				}
			}
		}
	}
	ll res = 0;
	for(int i = 0; i < 2; i++){
		for(int j = 1; j < 8; j++){
			(res+=dp[n][0][0][j][i])%=mod;
			for(int k = 0; k < 3; k++){
				(res+=dp[n][1][k][j][i])%=mod;
			}
		}
	}
	return res;
}

int main(){
	string A, B;
	cin>>A>>B;
	for(int i = A.size()-1; i >= 0; i--){
		if(A[i]!='0'){
			A[i] = A[i]-1;
			break;
		}
		A[i] = '9';
	}
	if(A[0]=='0') A = A.substr(1);
	cout<<(calc(B)-calc(A)+mod)%mod<<endl;
	return 0;
}
0