結果
問題 | No.260 世界のなんとか3 |
ユーザー | pione |
提出日時 | 2020-05-25 05:56:55 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 92 ms / 2,000 ms |
コード長 | 2,549 bytes |
コンパイル時間 | 1,598 ms |
コンパイル使用メモリ | 170,288 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-10-13 02:00:28 |
合計ジャッジ時間 | 3,851 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
10,872 KB |
testcase_01 | AC | 6 ms
10,864 KB |
testcase_02 | AC | 7 ms
10,880 KB |
testcase_03 | AC | 83 ms
10,880 KB |
testcase_04 | AC | 84 ms
10,880 KB |
testcase_05 | AC | 21 ms
10,880 KB |
testcase_06 | AC | 16 ms
10,880 KB |
testcase_07 | AC | 59 ms
10,880 KB |
testcase_08 | AC | 43 ms
10,976 KB |
testcase_09 | AC | 26 ms
10,880 KB |
testcase_10 | AC | 67 ms
10,880 KB |
testcase_11 | AC | 63 ms
10,880 KB |
testcase_12 | AC | 39 ms
10,876 KB |
testcase_13 | AC | 17 ms
10,828 KB |
testcase_14 | AC | 57 ms
10,932 KB |
testcase_15 | AC | 19 ms
10,992 KB |
testcase_16 | AC | 51 ms
10,880 KB |
testcase_17 | AC | 41 ms
10,880 KB |
testcase_18 | AC | 39 ms
10,848 KB |
testcase_19 | AC | 50 ms
10,884 KB |
testcase_20 | AC | 37 ms
10,880 KB |
testcase_21 | AC | 33 ms
10,828 KB |
testcase_22 | AC | 57 ms
10,944 KB |
testcase_23 | AC | 10 ms
10,812 KB |
testcase_24 | AC | 47 ms
10,880 KB |
testcase_25 | AC | 50 ms
10,964 KB |
testcase_26 | AC | 42 ms
10,996 KB |
testcase_27 | AC | 7 ms
10,940 KB |
testcase_28 | AC | 84 ms
11,008 KB |
testcase_29 | AC | 92 ms
10,992 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; // #define int long long #define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i) #define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i) #define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--) #define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--) #define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i) #define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i) #define SORT(v, n) sort(v, v + n); #define REVERSE(v, n) reverse(v, v+n); #define vsort(v) sort(v.begin(), v.end()); #define all(v) v.begin(), v.end() #define mp(n, m) make_pair(n, m); #define cout(d) cout<<d<<endl; #define coutd(d) cout<<std::setprecision(10)<<d<<endl; #define cinline(n) getline(cin,n); #define replace_all(s, b, a) replace(s.begin(),s.end(), b, a); #define PI (acos(-1)) #define FILL(v, n, x) fill(v, v + n, x); #define sz(x) long long(x.size()) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vs = vector<string>; using vpll = vector<pair<ll, ll>>; using tll = tuple<ll,ll,ll>; using vtll = vector<tuple<ll,ll,ll>>; using vb = vector<bool>; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e9; const ll MOD = 1e9+7; const ll LINF = 1e18; ll dp[10005][2][2][3][8]; // pos, isLess, has3, mod3, mod8 ll f(string s){ ll 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){ ll now=s[i]-'0'; rep(nxt,10){ if(nxt>now && j==0) continue; ll nj=j,nk=k,nl,nm; if(nxt<now) nj=1; if(nxt==3) nk=1; nl=(l*10+nxt)%3; nm=(m*10+nxt)%8; (dp[i+1][nj][nk][nl][nm]+=dp[i][j][k][l][m])%=MOD; } } ll ans=0; rep(j,2) rep(k,2) rep(l,3) rep(m,8){ if((k==1||l==0)&&m!=0) (ans+=dp[n][j][k][l][m])%=MOD; } return ans; } string minus1(string s){ ll n=s.size(); reverse(all(s)); rep(i,n){ if(s[i]!='0'){ s[i]--; break; } s[i]='9'; } if(s[n-1]=='0') s.resize(n-1); reverse(all(s)); return s; } signed main() { cin.tie( 0 ); ios::sync_with_stdio( false ); string a,b; cin>>a>>b; a=minus1(a); // cout<<a<<endl; ll ans=(f(b)-f(a)+MOD)%MOD; cout<<ans<<endl; }