結果

問題 No.260 世界のなんとか3
ユーザー 沙耶花
提出日時 2022-03-25 17:09:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 960 bytes
コンパイル時間 3,983 ms
コンパイル使用メモリ 258,244 KB
最終ジャッジ日時 2025-01-28 11:20:57
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000001

mint get(string s,bool f){
	vector dp(24,vector(2,vector<mint>(2,0)));
	dp[0][0][0] = 1;
	rep(i,s.size()){
		vector ndp(24,vector(2,vector<mint>(2,0)));
		int n = s[i] - '0';
		rep(j,24){
			rep(k,2){
				rep(l,2){
					
					rep(m,10){
						int jj = j*10 + m;
						jj %= 24;
						int kk = k;
						int ll = l;
						if(kk==0 && m>n)break;
						if(m<n)kk = 1;
						if(m==3)ll = 1;
						ndp[jj][kk][ll] += dp[j][k][l];
					}
				}
			}
		}
		swap(dp,ndp);
	}
	mint ret = 0;
	rep(i,24){
		rep(j,2){
			rep(k,2){
				if(!f&&j==0)continue;
				if((k==1 || i%3==0) && i%8!=0)ret += dp[i][j][k];
			}
		}
	}
	return ret;
}
		

int main(){
	
	string A,B;
	cin>>A>>B;
	mint ans = get(B,true);
	ans -= get(A,false);
	cout<<ans.val()<<endl;
	
	return 0;
}
0