提出 #6177286
ソースコード 拡げる
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) begin(x), end(x)
using namespace std;
template <class T, class U> inline void chmax(T & a, U const & b) { a = max<T>(a, b); }
template <class T, class U> inline void chmin(T & a, U const & b) { a = min<T>(a, b); }
template <typename X, typename T> auto make_vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_vectors(X x, Y y, Z z, Zs... zs) { auto cont = make_vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }
template <int32_t MOD>
struct mint {
int32_t value;
mint() : value() {}
mint(int64_t value_) : value(value_ < 0 ? value_ % MOD + MOD : value_ >= MOD ? value_ % MOD : value_) {}
inline mint<MOD> operator + (mint<MOD> other) const { int32_t c = this->value + other.value; return mint<MOD>(c >= MOD ? c - MOD : c); }
inline mint<MOD> operator - (mint<MOD> other) const { int32_t c = this->value - other.value; return mint<MOD>(c < 0 ? c + MOD : c); }
inline mint<MOD> operator * (mint<MOD> other) const { int32_t c = (int64_t)this->value * other.value % MOD; return mint<MOD>(c < 0 ? c + MOD : c); }
inline mint<MOD> & operator += (mint<MOD> other) { this->value += other.value; if (this->value >= MOD) this->value -= MOD; return *this; }
inline mint<MOD> & operator -= (mint<MOD> other) { this->value -= other.value; if (this->value < 0) this->value += MOD; return *this; }
inline mint<MOD> & operator *= (mint<MOD> other) { this->value = (int64_t)this->value * other.value % MOD; if (this->value < 0) this->value += MOD; return *this; }
inline mint<MOD> operator - () const { return mint<MOD>(this->value ? MOD - this->value : 0); }
mint<MOD> pow(uint64_t k) const {
mint<MOD> x = *this, y = 1;
for (; k; k >>= 1) {
if (k & 1) y *= x;
x *= x;
}
return y;
}
mint<MOD> inv() const {
assert (value != 0);
int64_t a = value, b = MOD;
int64_t x = 0, y = 1;
for (int64_t u = 1, v = 0; a; ) {
int64_t q = b / a;
x -= q * u; std::swap(x, u);
y -= q * v; std::swap(y, v);
b -= q * a; std::swap(b, a);
}
assert (value * x + MOD * y == b);
assert (b == 1);
return x;
}
inline mint<MOD> operator / (mint<MOD> other) const { return *this * other.inv(); }
inline mint<MOD> operator /= (mint<MOD> other) { return *this *= other.inv(); }
inline bool operator == (mint<MOD> other) const { return value == other.value; }
inline bool operator != (mint<MOD> other) const { return value != other.value; }
};
template <int32_t MOD> mint<MOD> operator * (int64_t value, mint<MOD> n) { return mint<MOD>(value) * n; }
template <int32_t MOD> std::ostream & operator << (std::ostream & out, mint<MOD> n) { return out << n.value; }
constexpr int MOD = 1e9 + 7;
mint<MOD> solve(int n, int k) {
int sqrt_n = floor(sqrt(n));
int len = 2 * sqrt_n + 1;
vector<mint<MOD> > cnt(len);
REP3 (j, 1, len) {
if (j <= sqrt_n) {
cnt[j] = 1;
} else {
int l = max(sqrt_n, n / (len - j + 1));
int r = max(sqrt_n, n / (len - j)); // (l, r]
cnt[j] = r - l;
}
}
auto dp = make_vectors(k, len, mint<MOD>());
dp[0] = cnt;
REP (i, k - 1) {
vector<mint<MOD> > acc(len + 1);
partial_sum(ALL(dp[i]), acc.begin() + 1);
REP3 (j, sqrt_n + 1, len) {
int l = max(sqrt_n, n / (len - j + 1));
int r = max(sqrt_n, n / (len - j)); // (l, r]
dp[i + 1][j] = cnt[j] * acc[n / r + 1];
dp[i + 1][n / r] = cnt[n / r] * acc[j + 1];
}
}
return accumulate(ALL(dp[k - 1]), mint<MOD>());
}
int main() {
int n, k; cin >> n >> k;
cout << solve(n, k) << endl;
return 0;
}
提出情報
提出日時 |
|
問題 |
F - Small Products |
ユーザ |
kimiyuki |
言語 |
C++14 (GCC 5.4.1) |
得点 |
600 |
コード長 |
4152 Byte |
結果 |
AC |
実行時間 |
87 ms |
メモリ |
25600 KiB |
ジャッジ結果
セット名 |
Sample |
All |
得点 / 配点 |
0 / 0 |
600 / 600 |
結果 |
|
|
セット名 |
テストケース |
Sample |
s1.txt, s2.txt, s3.txt |
All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, s1.txt, s2.txt, s3.txt |
ケース名 |
結果 |
実行時間 |
メモリ |
01.txt |
AC |
87 ms |
25600 KiB |
02.txt |
AC |
74 ms |
21760 KiB |
03.txt |
AC |
76 ms |
22420 KiB |
04.txt |
AC |
80 ms |
23572 KiB |
05.txt |
AC |
35 ms |
10240 KiB |
06.txt |
AC |
1 ms |
256 KiB |
09.txt |
AC |
76 ms |
22436 KiB |
10.txt |
AC |
1 ms |
256 KiB |
11.txt |
AC |
28 ms |
8064 KiB |
12.txt |
AC |
25 ms |
7296 KiB |
13.txt |
AC |
21 ms |
6272 KiB |
14.txt |
AC |
1 ms |
256 KiB |
s1.txt |
AC |
1 ms |
256 KiB |
s2.txt |
AC |
1 ms |
256 KiB |
s3.txt |
AC |
18 ms |
5376 KiB |