結果

問題 No.260 世界のなんとか3
ユーザー pythontanukipythontanuki
提出日時 2022-12-27 14:53:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,469 bytes
コンパイル時間 4,729 ms
コンパイル使用メモリ 263,720 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2023-08-14 05:55:18
合計ジャッジ時間 6,916 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,736 KB
testcase_01 AC 4 ms
7,496 KB
testcase_02 AC 4 ms
7,504 KB
testcase_03 WA -
testcase_04 AC 44 ms
7,544 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 14 ms
7,540 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 20 ms
7,676 KB
testcase_13 WA -
testcase_14 AC 29 ms
7,592 KB
testcase_15 AC 10 ms
7,536 KB
testcase_16 AC 26 ms
7,600 KB
testcase_17 WA -
testcase_18 AC 21 ms
7,748 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 24 ms
7,548 KB
testcase_25 AC 28 ms
7,528 KB
testcase_26 AC 20 ms
7,528 KB
testcase_27 AC 4 ms
7,472 KB
testcase_28 AC 34 ms
7,556 KB
testcase_29 AC 50 ms
7,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using mint = modint1000000007;
using C = complex<double>;
const int mod = 998244353;
const long long LINF = 1001002003004005006;
const int INF = 1001001001;
const double PI = acos(-1);
const double EPS = 1e-10;
const int di[4] = {-1,0,1,0};
const int dj[4] = {0,-1,0,1};
const int dx[8] = {1,1,1,0,0,-1,-1,-1};
const int dy[8] = {1,0,-1,1,-1,1,0,-1};
# define sz(x) (int)(x).size()
# define rsz(x,n) x.resize(n)
# define yosupo(x) {cout << (x) << endl; return 0;}
# define ll long long
# define fi first
# define se second
# define pb push_back
# define pf push_front
# define eb emplace_back
# define ef emplace_front
# define pob pop_back
# define pof pop_front
# define GET_MACRO(_1, _2, _3, NAME, ...) NAME
# define _rep(i, n) _rep2(i, 0, n)
# define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
# define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
# define srep(i, a, b) for(int i = a; i <= b; ++i)
# define all(obj) (obj).begin(), (obj).end()
# define rall(obj) (obj).rbegin(), (obj).rend()
inline void YesNo(bool f) { std::cout << (f? "Yes": "No") << std::endl; }
void read() {}
template <typename T, class... U> void read(T &t, U &...u) { cin >> t; read(u...); }
void writeln() { cout << endl; }
template <typename T, class... U, char sep = ' '> void writeln(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << sep; writeln(u...); }
# define Pll pair<ll, ll>
# define P pair<int,int>
# define bit(x,i) (((x) >> (i)) & 1)
# define equals(a, b) (fabs((a) - (b)) < EPS) // 誤差を考慮した同値判定
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { return os << "P(" << p.first << " " << p.second << ")";}
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
using vi = vc<int>; using vvi = vv<int>;
using vl = vc<ll>; using vvl = vv<ll>;
using vm = vc<mint>; using vvm = vv<mint>;

mint f(string s) {
    int n = sz(s);
    ll tot = 0;
    int flag = 0;
    ll mod8 = 0;
    rep(i,n) {
        int nd = s[i]-'0';
        if(nd == 3) flag |= 1;
        tot += nd;
        mod8 = (mod8*10+nd)%8;
    }
    return (mint)((tot%3 == 0 || flag) && mod8 != 0);
}

mint solve(string s) {
    //桁数, mod8, mod3, 3があるかないか, 以下フラグ
    mint dp[11000][8][3][2][2] = {};
    dp[0][0][0][0][0] = 1;
    int n = sz(s);
    rep(i,n) {
        int nd = s[i]-'0';
        rep(j,2) {
            if(j == 0) {
                rep(mod8,8) {
                    rep(mod3,3) {
                        if(nd == 3) {
                            dp[i+1][(mod8*10+nd)%8][(mod3+nd)%3][1][0] += dp[i][mod8][mod3][0][0];
                            dp[i+1][(mod8*10+nd)%8][(mod3+nd)%3][1][0] += dp[i][mod8][mod3][1][0];
                        } else {
                            dp[i+1][(mod8*10+nd)%8][(mod3+nd)%3][0][0] += dp[i][mod8][mod3][0][0];
                            dp[i+1][(mod8*10+nd)%8][(mod3+nd)%3][1][0] += dp[i][mod8][mod3][1][0];
                        }
                    }
                }
            } else {
                rep(k,nd) {
                    rep(mod8,8) {
                        rep(mod3,3) {
                            if(k == 3) {
                                dp[i+1][(mod8*10+k)%8][(mod3+k)%3][1][1] += dp[i][mod8][mod3][0][0];
                                dp[i+1][(mod8*10+k)%8][(mod3+k)%3][1][1] += dp[i][mod8][mod3][1][0];
                            } else {
                                dp[i+1][(mod8*10+k)%8][(mod3+k)%3][0][1] += dp[i][mod8][mod3][0][0];
                                dp[i+1][(mod8*10+k)%8][(mod3+k)%3][1][1] += dp[i][mod8][mod3][1][0];
                            }
                        }
                    }
                }
                rep(k,10) {
                    rep(mod8,8) {
                        rep(mod3,3) {
                            if(k == 3) {
                                dp[i+1][(mod8*10+k)%8][(mod3+k)%3][1][1] += dp[i][mod8][mod3][0][1];
                                dp[i+1][(mod8*10+k)%8][(mod3+k)%3][1][1] += dp[i][mod8][mod3][1][1];
                            } else {
                                dp[i+1][(mod8*10+k)%8][(mod3+k)%3][0][1] += dp[i][mod8][mod3][0][1];
                                dp[i+1][(mod8*10+k)%8][(mod3+k)%3][1][1] += dp[i][mod8][mod3][1][1];
                            }
                        }
                    }
                }
            }
        }
    }
    mint res = 0;
    rep(mod8,8) rep(mod3,3) rep(flag,2) rep(t,2) {
        if((mod8 != 0) && (mod3 == 0 || flag == 1)) res += dp[n][mod8][mod3][flag][t];
    }
    return res;
}

int main() {
    string s,t;
    read(s,t);
    mint res = solve(t).val() - solve(s).val() + f(s).val();
    cout << res.val() << endl;
}
















0