結果

問題 No.189 SUPER HAPPY DAY
ユーザー WarToks
提出日時 2019-06-11 21:41:01
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 6,969 bytes
コンパイル時間 1,172 ms
コンパイル使用メモリ 141,824 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-30 14:09:18
合計ジャッジ時間 2,187 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <algorithm>
#include <cstring>
#include <list>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <chrono>
#include <math.h>
using namespace std;
using lli = long long int;
using Vint = std::vector<int>;
using Vlli = std::vector<lli>;
using Wint = std::vector<Vint>;
using Wlli = std::vector<Vlli>;
using Vbool = std::vector<bool>;
using Wbool = std::vector<Vbool>;
using pii = std::pair<int, int>;
using pll = std::pair<lli, lli>;
template <class T>
using Vec = std::vector<T>;
constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const std::vector<std::pair<int, int>> DXDY = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
constexpr char BR = '\n';
#define DEBUG(x) std::cerr << #x << " = " << x << '\n';
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())
#define RSORT(A) std::sort((A).rbegin(), (A).rend())
#define ALL(A) (A).begin(), (A).end()
// (for vector) : 使 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())
template <class T> inline int argmin(std::vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(std::vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class S, class T> inline void chmax(S &a, T b){if(a < b) a = b;}
template <class S, class T> inline void chmin(S &a, T b){if(a > b) a = b;}
template <class T> inline void reverseSORT(Vec<T> &Array){
std::sort(Array.begin(), Array.end(), std::greater<T>());
}
inline int BitI(int k){return 1 << k;}
inline lli BitL(int k){return 1LL << k;}
inline void putsDouble(double d){printf("%.16lf\n", d);}
template <class T> inline std::string toString(T n){
if(n == 0) return "0";
std::string res;
if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;}
std::reverse(res.begin(), res.end()); return '-' + res;}
while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}
namespace MyFunc{
using LLi = long long int;
// GCD(a, b) ; a, b
inline LLi gcd(LLi a, LLi b){ while(b != 0){ a %= b; std::swap(a, b);} return a; }
// LCM(a, b) ; a, b
inline LLi lcm(LLi a, LLi b){ return (a * b) / MyFunc::gcd(a, b);}
//
inline LLi power(LLi a, LLi n){
LLi res = 1LL, waiting = a;
while(n != 0LL){ if((n & 1LL) != 0LL) res *= waiting; waiting *= waiting; n >>= 1;}
return res;
}
//
inline LLi power_mod(LLi a, LLi n, LLi mod_number___ = 1e9 + 7){
LLi res = 1LL, waiting = a;
while(n != 0LL){ if((n & 1LL) != 0LL){ res *= waiting; res %= mod_number___;}
waiting *= waiting; waiting %= mod_number___; n >>= 1; }
return res;
}
// Z/pZ ()
inline LLi inverse_mod(LLi a, LLi mod_number___ = 1e9 + 7){
return MyFunc::power_mod(a, mod_number___-2);
}
inline LLi inverse_mod_euclid(LLi a, LLi mod_number___ = 1e9+7){
LLi b = mod_number___, u = 1, v = 0;
while (b != 0) { LLi t = a / b; a -= t * b; std::swap(a, b);
u -= t * v; std::swap(u, v);}
u %= mod_number___; if (u < 0) u += mod_number___;
return u;
}
//
template <typename Integer_type>
inline bool isPrime(Integer_type n){
if(n < 2) return false; if(n == 2) return true; if(n % 2 == 0) return false;
for(Integer_type x = 3; x * x <= n; ++++x) if(n % x == 0) return false;
return true;
}
//  : n ≥ 1
inline std::vector<bool> primeTable(int n){
std::vector<bool> res(n+1, true); res[0] = false; res[1] = false;
for(int x = 2; x * x <= n; ++x) if(res[x]){
for(int i = 2 * x; i <= n; i += x){ res[i] = false; } }
return std::move(res);
}
//  ; {, }
template <typename Integer_type>
inline std::vector<std::pair<Integer_type, int>> prime_factorization(Integer_type n){
std::vector<std::pair<Integer_type, int>> res(0);
if(n <= 0) return std::move(res); //  : n 0
if(n % 2 == 0){
n /= 2; int cnt = 1; while(n % 2 == 0){ n /= 2; cnt++;}
res.emplace_back(make_pair(2, cnt));
}
Integer_type x = 3;
while(x * x <= n){
if(n % x == 0){
n /= x; int cnt = 1; while(n % x == 0){ n /= x; cnt++; }
res.emplace_back(make_pair(x, cnt));
} ++++x;
} if(n > 1) res.emplace_back(make_pair(n, 1));
return std::move(res);
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
constexpr int MAX_SIZE = 200 + 2;
constexpr int thisMOD = 1e9+9;
char M[MAX_SIZE], D[MAX_SIZE];
int main(void){
scanf("%s%s", M, D);
const int nM = strlen(M), nD = strlen(D);
// DP_M[i][j][k] := M, i j (k)
// ~> DP_M[j] : j
// DP_D[i][j][k] := D
const int mxM = 9 * nM, mxD = 9 * nD;
Vint DP_M(mxM+1, 0), DP_D(mxD+1, 0);
Vint nxtM = DP_M;
int ever = 0;
REP(i, nM){ // M i
FOReq(j, 0, mxM) nxtM[j] = 0; //
int d = M[i] - '0';
// 使
FOReq(j, 0, mxM) REP(k, 10){nxtM[j+k] += DP_M[j]; nxtM[j+k] %= thisMOD;}
//
REP(k, d) nxtM[ever+k]++;
ever += d;
std::swap(DP_M, nxtM);
} DP_M[ever]++;
Vint nxtD = DP_D; ever = 0;
REP(i, nD){
FOReq(j, 0, mxD) nxtD[j] = 0;
int d = D[i] - '0';
FOReq(j, 0, mxD) REP(k, 10){nxtD[j+k] += DP_D[j]; nxtD[j+k] %= thisMOD;}
REP(k, d) nxtD[ever+k]++;
ever += d;
std::swap(DP_D, nxtD);
} DP_D[ever]++;
lli res = 0; int mn = (mxM >= mxD) ? mxD : mxM;
FOReq(a, 1, mn){
res += (static_cast<lli>(DP_D[a])) * DP_M[a];
res %= thisMOD;
}
printf("%lld\n", res);
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0