結果
問題 | No.1043 直列大学 |
ユーザー | qLethon |
提出日時 | 2020-05-01 22:51:06 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 171 ms / 2,000 ms |
コード長 | 4,700 bytes |
コンパイル時間 | 2,077 ms |
コンパイル使用メモリ | 208,292 KB |
実行使用メモリ | 163,616 KB |
最終ジャッジ日時 | 2024-06-02 02:58:39 |
合計ジャッジ時間 | 5,836 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 8 ms
10,360 KB |
testcase_01 | AC | 7 ms
8,676 KB |
testcase_02 | AC | 13 ms
14,820 KB |
testcase_03 | AC | 8 ms
8,680 KB |
testcase_04 | AC | 6 ms
8,680 KB |
testcase_05 | AC | 7 ms
8,680 KB |
testcase_06 | AC | 6 ms
8,676 KB |
testcase_07 | AC | 10 ms
11,784 KB |
testcase_08 | AC | 10 ms
11,788 KB |
testcase_09 | AC | 91 ms
85,372 KB |
testcase_10 | AC | 108 ms
101,032 KB |
testcase_11 | AC | 159 ms
150,384 KB |
testcase_12 | AC | 171 ms
163,616 KB |
testcase_13 | AC | 143 ms
137,088 KB |
testcase_14 | AC | 156 ms
144,828 KB |
testcase_15 | AC | 167 ms
158,188 KB |
testcase_16 | AC | 149 ms
141,736 KB |
testcase_17 | AC | 112 ms
104,908 KB |
testcase_18 | AC | 115 ms
104,972 KB |
testcase_19 | AC | 138 ms
133,868 KB |
testcase_20 | AC | 109 ms
102,408 KB |
testcase_21 | AC | 131 ms
123,852 KB |
testcase_22 | AC | 136 ms
129,312 KB |
testcase_23 | AC | 170 ms
162,060 KB |
testcase_24 | AC | 120 ms
115,120 KB |
testcase_25 | AC | 143 ms
135,512 KB |
testcase_26 | AC | 151 ms
144,896 KB |
testcase_27 | AC | 79 ms
72,784 KB |
testcase_28 | AC | 141 ms
133,848 KB |
testcase_29 | AC | 47 ms
46,232 KB |
testcase_30 | AC | 108 ms
101,920 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; template <std::uint_fast64_t Modulus> class modint { using u64 = std::uint_fast64_t; u64 a; public: template <class INT> constexpr modint(const INT x = 0) noexcept : a(x >= 0 ? x % Modulus : x % Modulus + Modulus) {} constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) { a += Modulus; } a -= rhs.a; return *this; } constexpr modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint &operator/=(modint rhs) noexcept { u64 exp = Modulus - 2; while (exp) { if (exp % 2) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } constexpr bool operator<(const modint& rhs) const noexcept {return this->a < rhs.a;} constexpr bool operator>(const modint& rhs) const noexcept {return rhs < *this;} constexpr bool operator<=(const modint& rhs) const noexcept {return !(*this > rhs);} constexpr bool operator>=(const modint& rhs) const noexcept {return !(*this < rhs);} constexpr bool operator==(const modint& rhs) const noexcept {return this->a == rhs.a;} constexpr bool operator!=(const modint& rhs) const noexcept {return !(*this == rhs);} constexpr modint& operator++() noexcept { *this += modint(1); return *this; } constexpr modint operator++(int) noexcept { modint tmp(*this); ++(*this); return tmp; } constexpr modint& operator--() noexcept { *this -= modint(1); return *this; } constexpr modint operator--(int) noexcept { modint tmp(*this); --(*this); return tmp; } constexpr modint operator-() const noexcept { return modint(0) - *this; } template <std::uint_fast64_t M> friend constexpr std::ostream& operator<<(std::ostream& os, const modint<M>& rhs) noexcept { os << rhs.a; return os; } template <std::uint_fast64_t M> friend constexpr std::istream& operator>>(std::istream& is, modint<M>& rhs) noexcept { int64_t tmp; is >> tmp; rhs = modint(tmp); return is; } constexpr modint pow(const u64 k) const noexcept { if (k == 0) return 1; if (k % 2 == 0){ modint res = pow(k / 2); return res * res; } return pow(k - 1) * modint(*this); } template <typename T> operator const T (){return a;} }; int main(){ const constexpr int64_t p = 1e9 + 7; using mint = modint<p>; int n, m; cin >> n >> m; vector<int> V(n), R(m); copy_n(istream_iterator<int>(cin), n, V.begin()); copy_n(istream_iterator<int>(cin), m, R.begin()); int a, b; cin >> a >> b; const int sup = 1e5; vector<vector<mint>> DPV(n + 1, vector<mint>(sup + 1)), DPR(m + 1, vector<mint>(sup + 1)); DPV[0][0] = 1; DPR[0][0] = 1; for (int i = 0; i < n; i++){ for (int j = 0; j <= sup; j++){ DPV[i + 1][j] += DPV[i][j]; if (j + V[i] <= sup) DPV[i + 1][j + V[i]] += DPV[i][j]; } } for (int i = 0; i < m; i++){ for (int j = 0; j <= sup; j++){ DPR[i + 1][j] += DPR[i][j]; if (j + R[i] <= sup) DPR[i + 1][j + R[i]] += DPR[i][j]; } } mint ans = 0; vector<mint> SV(sup + 2), SR(sup + 2); for (int i = 0; i <= sup; i++){ SV[i + 1] = SV[i] + DPV[n][i]; SR[i + 1] = SR[i] + DPR[m][i]; } for (int64_t r = 0; r <= sup; r++){ int64_t l = a * r, right = b * r; if (sup < l) break; ans += DPR[m][r] * (SV[min(int64_t(sup) + 1, right + 1)] - SV[l]); } cout << ans - mint(1) << endl; }