結果

問題 No.260 世界のなんとか3
ユーザー kyuridenamidakyuridenamida
提出日時 2016-08-25 16:15:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,990 bytes
コンパイル時間 809 ms
コンパイル使用メモリ 100,660 KB
実行使用メモリ 8,484 KB
最終ジャッジ日時 2024-04-25 15:19:50
合計ジャッジ時間 3,013 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,264 KB
testcase_01 AC 3 ms
7,208 KB
testcase_02 AC 3 ms
7,204 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 4 ms
7,252 KB
testcase_28 AC 76 ms
8,404 KB
testcase_29 AC 75 ms
8,368 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));
	}

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

}
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