結果
問題 | No.1201 お菓子配り-4 |
ユーザー | 👑 hos.lyric |
提出日時 | 2020-08-28 21:39:22 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,104 bytes |
コンパイル時間 | 1,488 ms |
コンパイル使用メモリ | 112,964 KB |
実行使用メモリ | 10,148 KB |
最終ジャッジ日時 | 2024-11-14 00:02:59 |
合計ジャッジ時間 | 33,904 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 90 ms
6,816 KB |
testcase_01 | AC | 1,229 ms
6,816 KB |
testcase_02 | AC | 1,768 ms
6,816 KB |
testcase_03 | AC | 858 ms
6,816 KB |
testcase_04 | AC | 419 ms
6,816 KB |
testcase_05 | AC | 1,043 ms
6,820 KB |
testcase_06 | AC | 159 ms
6,820 KB |
testcase_07 | AC | 471 ms
6,816 KB |
testcase_08 | AC | 1,312 ms
6,816 KB |
testcase_09 | AC | 964 ms
6,816 KB |
testcase_10 | AC | 8 ms
6,820 KB |
testcase_11 | AC | 250 ms
6,816 KB |
testcase_12 | AC | 2,012 ms
6,820 KB |
testcase_13 | AC | 56 ms
6,816 KB |
testcase_14 | AC | 28 ms
6,820 KB |
testcase_15 | AC | 1,589 ms
6,816 KB |
testcase_16 | AC | 481 ms
6,820 KB |
testcase_17 | AC | 622 ms
6,820 KB |
testcase_18 | AC | 101 ms
6,820 KB |
testcase_19 | AC | 96 ms
6,816 KB |
testcase_20 | AC | 2 ms
6,816 KB |
testcase_21 | AC | 2 ms
6,820 KB |
testcase_22 | AC | 1 ms
6,820 KB |
testcase_23 | AC | 2 ms
6,820 KB |
testcase_24 | AC | 2 ms
6,816 KB |
testcase_25 | AC | 2 ms
6,820 KB |
testcase_26 | AC | 2 ms
6,816 KB |
testcase_27 | AC | 2 ms
6,820 KB |
testcase_28 | AC | 2 ms
6,816 KB |
testcase_29 | AC | 2 ms
6,820 KB |
testcase_30 | AC | 2,548 ms
6,816 KB |
testcase_31 | AC | 2,547 ms
6,816 KB |
testcase_32 | AC | 2,553 ms
6,816 KB |
testcase_33 | AC | 2,544 ms
6,820 KB |
testcase_34 | AC | 2,533 ms
6,820 KB |
testcase_35 | TLE | - |
ソースコード
#pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target ("avx") #include <cassert> #include <cmath> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using Int = long long; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } template<int M_> struct ModInt { static constexpr int M = M_; int x; constexpr ModInt() : x(0) {} constexpr ModInt(long long x_) : x(x_ % M) { if (x < 0) x += M; } ModInt &operator+=(const ModInt &a) { x += a.x; if (x >= M) x -= M; return *this; } ModInt &operator-=(const ModInt &a) { x -= a.x; if (x < 0) x += M; return *this; } ModInt &operator*=(const ModInt &a) { x = static_cast<int>((static_cast<long long>(x) * a.x) % M); return *this; } ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); } ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); } ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); } ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); } ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); } ModInt operator-() const { return ModInt(-x); } ModInt pow(long long e) const { if (e < 0) return inv().pow(-e); ModInt x2 = x, xe = 1; for (; e; e >>= 1) { if (e & 1) xe *= x2; x2 *= x2; } return xe; } ModInt inv() const { int a = x, b = M, y = 1, z = 0, t; for (; ; ) { t = a / b; a -= t * b; if (a == 0) { assert(b == 1 || b == -1); return ModInt(b * z); } y -= t * z; t = b / a; b -= t * a; if (b == 0) { assert(a == 1 || a == -1); return ModInt(a * y); } z -= t * y; } } friend ModInt operator+(long long a, const ModInt &b) { return (ModInt(a) += b); } friend ModInt operator-(long long a, const ModInt &b) { return (ModInt(a) -= b); } friend ModInt operator*(long long a, const ModInt &b) { return (ModInt(a) *= b); } friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; } }; constexpr int MO = 1000000007; using Mint = ModInt<MO>; // floor(a / b) Int divFloor(Int a, Int b) { return a / b - (((a ^ b) < 0 && a % b != 0) ? 1 : 0); } // sum_{x=l}^r floor((a x + b) / m) // m > 0 constexpr __int128_t ONE = 1; Mint sumFloors(Int m, Int a, Int b, Int l, Int r) { __int128_t sum = 0; for (; l <= r; ) { const Int q = divFloor(a, m); const Int aa = a - q * m; const Int ll = divFloor(aa * l + b, m) + 1; const Int rr = divFloor(aa * r + b, m); // sum += Mint(q) * Mint((r + 1) * r / 2 - l * (l - 1) / 2) + Mint(r) * Mint(rr) - Mint(l - 1) * Mint(ll - 1) + Mint(rr - ll + 1); sum += ONE * q * ((r + 1) * r / 2 - l * (l - 1) / 2) + ONE * r * rr - ONE * (l - 1) * (ll - 1) + (rr - ll + 1); a = m; m = aa; l = -rr; r = -ll; } return Mint((Int)(sum % MO)); } int M, N; vector<Int> A, B; int main() { for (; ~scanf("%d%d", &M, &N); ) { A.resize(M); for (int i = 0; i < M; ++i) { scanf("%lld", &A[i]); } B.resize(N); for (int j = 0; j < N; ++j) { scanf("%lld", &B[j]); } if(M>2000)exit(1); if(N>2000)exit(1); Mint ans = 0; for (int i = 0; i < M; ++i) for (int j = 0; j < N; ++j) { ans += sumFloors(B[j], A[i], 0, 1, B[j]); } ans *= 2; printf("%d\n", ans.x); } return 0; }