結果

問題 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
コンパイル時間 587 ms
コンパイル使用メモリ 79,732 KB
実行使用メモリ 11,912 KB
最終ジャッジ日時 2023-08-07 13:56:39
合計ジャッジ時間 4,175 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,652 KB
testcase_01 AC 4 ms
11,608 KB
testcase_02 AC 4 ms
11,604 KB
testcase_03 AC 174 ms
11,716 KB
testcase_04 AC 173 ms
11,776 KB
testcase_05 AC 36 ms
11,680 KB
testcase_06 AC 27 ms
11,608 KB
testcase_07 AC 119 ms
11,700 KB
testcase_08 AC 83 ms
11,660 KB
testcase_09 AC 48 ms
11,892 KB
testcase_10 AC 133 ms
11,648 KB
testcase_11 AC 125 ms
11,640 KB
testcase_12 AC 78 ms
11,748 KB
testcase_13 AC 25 ms
11,856 KB
testcase_14 AC 114 ms
11,636 KB
testcase_15 AC 34 ms
11,632 KB
testcase_16 AC 101 ms
11,912 KB
testcase_17 AC 80 ms
11,644 KB
testcase_18 AC 77 ms
11,644 KB
testcase_19 AC 100 ms
11,704 KB
testcase_20 AC 72 ms
11,692 KB
testcase_21 AC 64 ms
11,632 KB
testcase_22 AC 114 ms
11,644 KB
testcase_23 AC 15 ms
11,608 KB
testcase_24 AC 90 ms
11,712 KB
testcase_25 AC 113 ms
11,632 KB
testcase_26 AC 67 ms
11,700 KB
testcase_27 AC 5 ms
11,752 KB
testcase_28 AC 173 ms
11,668 KB
testcase_29 AC 219 ms
11,644 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