結果

問題 No.129 お年玉(2)
ユーザー tanimani364tanimani364
提出日時 2020-06-29 22:03:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 5,893 bytes
コンパイル時間 2,006 ms
コンパイル使用メモリ 199,016 KB
実行使用メモリ 82,188 KB
最終ジャッジ日時 2023-09-26 11:20:44
合計ジャッジ時間 7,552 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
81,876 KB
testcase_01 RE -
testcase_02 AC 38 ms
82,140 KB
testcase_03 AC 38 ms
81,952 KB
testcase_04 AC 38 ms
81,876 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 38 ms
81,880 KB
testcase_13 AC 38 ms
81,872 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 39 ms
81,876 KB
testcase_30 AC 39 ms
82,036 KB
testcase_31 AC 39 ms
81,876 KB
testcase_32 AC 39 ms
81,868 KB
testcase_33 AC 39 ms
81,920 KB
testcase_34 AC 38 ms
82,032 KB
testcase_35 AC 38 ms
81,876 KB
testcase_36 AC 38 ms
81,872 KB
testcase_37 AC 39 ms
81,872 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 38 ms
81,868 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 38 ms
81,860 KB
testcase_47 WA -
testcase_48 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 静的メンバ関数 ‘static int ArbitraryModInt::set_mod(int)’ 内:
main.cpp:177:3: 警告: 非 void を戻す関数内に return 文がありません [-Wreturn-type]
  177 |   }
      |   ^

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

template<int mod>
struct Modint{
    int x;
    Modint():x(0){}
    Modint(int64_t y):x((y%mod+mod)%mod){}

    Modint &operator+=(const Modint &p){
			if((x+=p.x)>=mod)
				x -= mod;
			return *this;
		}

		Modint &operator-=(const Modint &p){
			if((x+=mod-p.x)>=mod)
				x -= mod;
			return *this;
		}

		Modint &operator*=(const Modint &p){
			x = (1LL * x * p.x) % mod;
			return *this;
		}

		Modint &operator/=(const Modint &p){
			*this *= p.inverse();
			return *this;
		}

		Modint operator-() const { return Modint(-x); }
		Modint operator+(const Modint &p) const{
			return Modint(*this) += p;
		}
		Modint operator-(const Modint &p) const{
			return Modint(*this) -= p;
		}
		Modint operator*(const Modint &p) const{
			return Modint(*this) *= p;
		}
		Modint operator/(const Modint &p) const{
			return Modint(*this) /= p;
		}

		bool operator==(const Modint &p) const { return x == p.x; }
		bool operator!=(const Modint &p) const{return x != p.x;}

		Modint inverse() const{//非再帰拡張ユークリッド
			int a = x, b = mod, u = 1, v = 0;
			while(b>0){
				int t = a / b;
				swap(a -= t * b, b);
				swap(u -= t * v, v);
			}
			return Modint(u);
		}

		Modint pow(int64_t n) const{//繰り返し二乗法
			Modint ret(1), mul(x);
			while(n>0){
				if(n&1)
					ret *= mul;
				mul *= mul;
				n >>= 1;
			}
			return ret;
		}

		friend ostream &operator<<(ostream &os,const Modint &p){
			return os << p.x;
		}
};

using modint = Modint<mod>;

template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;

  Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }

  inline T fact(int k) const { return _fact[k]; }

  inline T rfact(int k) const { return _rfact[k]; }

  inline T inv(int k) const { return _inv[k]; }

  T P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }

  T C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }

  T H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};

struct ArbitraryModInt {

  int x;

  ArbitraryModInt() : x(0) {}

  ArbitraryModInt(int64_t y) : x(y >= 0 ? y % mod() : (mod() - (-y) % mod()) % mod()) {}

  static int &mod() {
    static int mod = 0;
    return mod;
  }

  static int set_mod(int md) {
    mod() = md;
  }

  ArbitraryModInt &operator+=(const ArbitraryModInt &p) {
    if((x += p.x) >= mod()) x -= mod();
    return *this;
  }

  ArbitraryModInt &operator-=(const ArbitraryModInt &p) {
    if((x += mod() - p.x) >= mod()) x -= mod();
    return *this;
  }

  ArbitraryModInt &operator*=(const ArbitraryModInt &p) {
    unsigned long long a = (unsigned long long) x * p.x;
    unsigned xh = (unsigned) (a >> 32), xl = (unsigned) a, d, m;
    asm("divl %4; \n\t" : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" (mod()));
    x = m;
    return *this;
  }

  ArbitraryModInt &operator/=(const ArbitraryModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ArbitraryModInt operator-() const { return ArbitraryModInt(-x); }

  ArbitraryModInt operator+(const ArbitraryModInt &p) const { return ArbitraryModInt(*this) += p; }

  ArbitraryModInt operator-(const ArbitraryModInt &p) const { return ArbitraryModInt(*this) -= p; }

  ArbitraryModInt operator*(const ArbitraryModInt &p) const { return ArbitraryModInt(*this) *= p; }

  ArbitraryModInt operator/(const ArbitraryModInt &p) const { return ArbitraryModInt(*this) /= p; }

  bool operator==(const ArbitraryModInt &p) const { return x == p.x; }

  bool operator!=(const ArbitraryModInt &p) const { return x != p.x; }

  ArbitraryModInt inverse() const {
    int a = x, b = mod(), u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ArbitraryModInt(u);
  }

  ArbitraryModInt pow(int64_t n) const {
    ArbitraryModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ArbitraryModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ArbitraryModInt &a) {
    int64_t t;
    is >> t;
    a = ArbitraryModInt(t);
    return (is);
  }
};

ll dp[10005][1005];

void comb(){
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	for(int i=1;i<=10000;++i){
		dp[i][0]=1;
		for(int j=1;j<=1000;++j){
			dp[i][j]=(dp[i-1][j-1]+dp[i-1][j])%1000000000;
		}
	}
}

void solve()
{
	ll n,m;
	cin>>n>>m;
	ll a=m*1000;
	n%=a;
	n=(n-n%1000)/1000;
	comb();
	cout<<dp[m][n]<<"\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
0