結果
| 問題 |
No.260 世界のなんとか3
|
| コンテスト | |
| ユーザー |
aim_cpo
|
| 提出日時 | 2017-09-11 12:20:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 199 ms / 2,000 ms |
| コード長 | 2,162 bytes |
| コンパイル時間 | 1,224 ms |
| コンパイル使用メモリ | 94,156 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-11-07 16:53:35 |
| 合計ジャッジ時間 | 4,667 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
//fill((int*)d, (int*)(d + lengthof(d)), -1);
using namespace std;
string a,b;
const ll MOD=(ll)1e9+7;
ll dp[10010][2][2][3][8];
inline ll solve(string s){
int n=(int)s.length();
dp[0][0][0][0][0]=1;
for(int i=0;i<n;i++){
for(int j=0;j<2;j++){
for(int k=0;k<2;k++){
for(int l=0;l<3;l++){
for(int m=0;m<8;m++){
int lim=j?9:s[i]-'0';
for(int d=0;d<lim+1;d++){
(dp[i+1][j || d<lim][k || d==3][(l*10+d)%3][(m*10+d)%8]+=dp[i][j][k][l][m])%=MOD;
}
}
}
}
}
}
ll res=0;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
for(int k=0;k<3;k++){
for(int l=0;l<8;l++){
if((j || k==0) && l!=0)
(res+=dp[n][i][j][k][l])%=MOD;
}
}
}
}
return res;
}
inline string min1(string s){
for(int i=s.length()-1;i>=0;i--){
if(s[i]-'0'-1<0){
s[i]='9';
}else{
s[i]-=1;
break;
}
}
for(int i=0;i<(int)s.length();i++){
if(s=="0")break;
if(s[i]=='0')s=s.substr(1,s.length()-1);
else break;
}
return s;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout<<fixed;
#ifdef LOCAL_DEFINE
freopen("in", "r", stdin);
freopen("out","w",stdout);
#endif
cin>>a>>b;
ll ans=solve(b);
for(int i=0;i<(int)a.length()+5;i++){
for(int j=0;j<2;j++)for(int k=0;k<2;k++)for(int l=0;l<3;l++)for(int m=0;m<8;m++)dp[i][j][k][l][m]=0;
}
//cout<<ans<<"\n";
string aa=min1(a);
//cout<<aa<<endl;
ll ansa=solve(aa);
//cout<<ansa<<"\n";
cout<<(ans+MOD-ansa)%MOD<<"\n";
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
aim_cpo