結果
問題 | No.260 世界のなんとか3 |
ユーザー |
![]() |
提出日時 | 2018-03-13 15:35:37 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 87 ms / 2,000 ms |
コード長 | 959 bytes |
コンパイル時間 | 2,077 ms |
コンパイル使用メモリ | 160,648 KB |
実行使用メモリ | 10,996 KB |
最終ジャッジ日時 | 2024-11-22 04:19:44 |
合計ジャッジ時間 | 3,987 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include<bits/stdc++.h> #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) (v).begin(),(v).end() #define int long long using namespace std; //----------------------------------------------------------------------- const int mod=1e9+7; int dp[10010][2][2][3][8]; //pos,less,has3,mod3,mod8 int solve(string s,bool less){ int N=s.size(); memset(dp,0,sizeof(dp)); dp[0][0][0][0][0]=1; REP(i,N) REP(j,2) REP(k,2) REP(l,3) REP(m,8){ int lim=j?9:s[i]-'0'; REP(d,lim+1){ (dp[i+1][j|d<lim][k|d==3][(l+d)%3][(m*10+d)%8]+=dp[i][j][k][l][m])%=mod; } } int ret=0; REP(k,2) REP(l,3) REP(m,8){ if((k or l==0) and m!=0){ if(!less) (ret+=dp[N][0][k][l][m])%=mod; (ret+=dp[N][1][k][l][m])%=mod; } } return ret; } signed main() { string a,b; cin>>a>>b; int r1=solve(a,1); int r2=solve(b,0); int ans=(r2-r1+mod)%mod; cout<<ans<<endl; }