結果
問題 | No.260 世界のなんとか3 |
ユーザー | aim_cpo |
提出日時 | 2017-09-11 12:20:57 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 199 ms / 2,000 ms |
コード長 | 2,162 bytes |
コンパイル時間 | 779 ms |
コンパイル使用メモリ | 95,060 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-04-25 06:43:01 |
合計ジャッジ時間 | 3,983 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 156 ms
10,880 KB |
testcase_04 | AC | 161 ms
11,008 KB |
testcase_05 | AC | 33 ms
6,400 KB |
testcase_06 | AC | 22 ms
5,376 KB |
testcase_07 | AC | 106 ms
9,856 KB |
testcase_08 | AC | 77 ms
9,856 KB |
testcase_09 | AC | 42 ms
6,784 KB |
testcase_10 | AC | 119 ms
9,344 KB |
testcase_11 | AC | 117 ms
10,368 KB |
testcase_12 | AC | 72 ms
8,704 KB |
testcase_13 | AC | 21 ms
5,376 KB |
testcase_14 | AC | 107 ms
10,112 KB |
testcase_15 | AC | 30 ms
5,376 KB |
testcase_16 | AC | 93 ms
8,832 KB |
testcase_17 | AC | 78 ms
7,424 KB |
testcase_18 | AC | 75 ms
6,912 KB |
testcase_19 | AC | 92 ms
9,984 KB |
testcase_20 | AC | 63 ms
7,552 KB |
testcase_21 | AC | 56 ms
7,936 KB |
testcase_22 | AC | 98 ms
8,704 KB |
testcase_23 | AC | 10 ms
5,376 KB |
testcase_24 | AC | 84 ms
9,344 KB |
testcase_25 | AC | 104 ms
11,008 KB |
testcase_26 | AC | 62 ms
11,008 KB |
testcase_27 | AC | 2 ms
5,376 KB |
testcase_28 | AC | 157 ms
11,008 KB |
testcase_29 | AC | 199 ms
11,008 KB |
ソースコード
#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; }