結果

問題 No.315 世界のなんとか3.5
ユーザー gabriel55_gabriel55_
提出日時 2023-01-15 16:52:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 2,273 bytes
コンパイル時間 3,733 ms
コンパイル使用メモリ 263,288 KB
最終ジャッジ日時 2025-02-10 03:37:21
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 TLE * 10 MLE * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#if !__INCLUDE_LEVEL__
#include __FILE__

using mint = modint1000000007;

int main(void){
   string s, t;
   cin >> s >> t;
   ll p;
   cin >> p;
   mint ans = 0;
   rep(x,2){
      swap(s, t);
      ll n = s.length();
      vector dp(n+1, vector<vector<vector<vector<mint>>>>(2, vector<vector<vector<mint>>>(2, vector<vector<mint>>(3, vector<mint>(p, 0)))));
      dp[0][0][0][0][0] = 1;
      rep(i,n) rep(j,2) rep(k,2) rep(l,3) rep(m,p) {
         ll lim = j ? 9 : s[i] - '0';
         rep(d,lim+1) dp[i+1][j || d < lim][k || d == 3][(l+d)%3][(10*m+d)%p] += dp[i][j][k][l][m];
      }

      rep(j,2) rep(k,2) rep(l,3) m_99(m,1,p) {
         if(x && !j) continue;
         if(k || !l) {
            if(x) ans -= dp[n][j][k][l][m];
            else ans += dp[n][j][k][l][m];
         }
      }
   }
   cout << ans.val() << '\n';
}

/*---------------------------------------------------------------------------------------------------
      ○______
       ||      |
       ||   ●   |
       ||      |
        || ̄ ̄ ̄ ̄ ̄
       ||  君が代は
   ∧__,,∧||  千代に八千代に
  ( `・ω・||    さざれ石の巌となりて
   ヽ  つ0     こけのむすまで
   し―-J
---------------------------------------------------------------------------------------------------*/

#else
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using ldb = long double;
using P = pair<ll, ll>;
#define fi first
#define se second
#define m_99(i,a,b) for (ll i = a, i##_range = (b); i < i##_range; i++)
#define rep(i,a) m_99(i,0,a)
template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; }
template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; }
#ifdef LOCAL
#include <debug_print.hpp>
#define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (static_cast<void>(0))
#endif
struct initialise { initialise() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }__INI__;
const ll inf = 1LL << 60;
const ll dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
#endif
0