結果

問題 No.260 世界のなんとか3
ユーザー kyuridenamidakyuridenamida
提出日時 2016-08-25 16:16:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 2,009 bytes
コンパイル時間 877 ms
コンパイル使用メモリ 100,288 KB
実行使用メモリ 8,500 KB
最終ジャッジ日時 2024-04-25 15:19:55
合計ジャッジ時間 4,019 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,200 KB
testcase_01 AC 4 ms
7,208 KB
testcase_02 AC 4 ms
7,200 KB
testcase_03 AC 160 ms
8,296 KB
testcase_04 AC 160 ms
8,372 KB
testcase_05 AC 34 ms
7,780 KB
testcase_06 AC 24 ms
7,532 KB
testcase_07 AC 110 ms
8,188 KB
testcase_08 AC 80 ms
8,320 KB
testcase_09 AC 45 ms
7,788 KB
testcase_10 AC 125 ms
8,176 KB
testcase_11 AC 118 ms
8,280 KB
testcase_12 AC 73 ms
8,044 KB
testcase_13 AC 23 ms
7,472 KB
testcase_14 AC 108 ms
8,064 KB
testcase_15 AC 30 ms
7,520 KB
testcase_16 AC 93 ms
8,064 KB
testcase_17 AC 74 ms
7,788 KB
testcase_18 AC 71 ms
7,760 KB
testcase_19 AC 93 ms
8,208 KB
testcase_20 AC 67 ms
7,808 KB
testcase_21 AC 59 ms
7,928 KB
testcase_22 AC 106 ms
8,080 KB
testcase_23 AC 13 ms
7,284 KB
testcase_24 AC 83 ms
8,116 KB
testcase_25 AC 84 ms
8,500 KB
testcase_26 AC 84 ms
8,464 KB
testcase_27 AC 4 ms
7,164 KB
testcase_28 AC 159 ms
8,368 KB
testcase_29 AC 162 ms
8,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <unordered_set>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <fstream>
#include <sstream>
#include <complex>
#include <bitset>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rev(i,n) for(int i=(n)-1;(i)>=0;(i)--)
#define all(a) (a).begin(),(a).end()
#define pb(a) push_back(a)
#define bitcount(b) __builtin_popcount(b)
template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
template<typename T> void operator>>(vector<T>& a, int b) {while(b--)if(!a.empty())a.pop_back();}
bool isprime(int n){ if(n<2)return false;  for(int i=2;i*i<=n;i++)if(n%i==0)return false;  return true;} 

int MOD = 1e9+7;

string s;
int dp[10100][3][8][2][2];

long long dfs(int x,int mod3,int mod8,int lim,int three){
	if( x == s.size() ) return (mod3 == 0 or three) and mod8 > 0;

	if( dp[x][mod3][mod8][lim][three] != -1 ) return  dp[x][mod3][mod8][lim][three];
	int ans = 0;
	for(int i = 0 ; i <= (lim?9:s[x]-'0') ; i++){
		ans += dfs(x+1,(mod3*10+i)%3,(mod8*10+i)%8,lim||(i<s[x]-'0'),three||(i==3));
		ans %= MOD;
	}

	return dp[x][mod3][mod8][lim][three] = ans % MOD;

}
long long f(string s_){
	memset(dp,-1,sizeof(dp));
	s = s_;
	return dfs(0,0,0,0,0);
}

int is_sol(string s){
	int mod3 = 0;
	int mod8 = 0;
	int three = 0;
	for( auto c : s ) if( c == '3') three = 1;
	
	for( auto c : s ) mod3 = (mod3*10+c-'0')%3;
	for( auto c : s ) mod8 = (mod8*10+c-'0')%8;
	return (three or mod3 == 0) and mod8 > 0;
}

int main(){
	string A,B;
	cin >> A >> B;
	while( A.size() < B.size() ) A = "0" + A;
	while( B.size() < A.size() ) B = "0" + B;
	cout << ((f(B) - f(A) + is_sol(A))%MOD+MOD)%MOD << endl;

}
0