QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#164663 | #6854. Umamusume | jrjyy | AC ✓ | 4ms | 3700kb | C++20 | 3.0kb | 2023-09-05 12:08:02 | 2023-09-05 12:08:02 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
template <typename T> constexpr T power(T a, i64 b) {
T c{1}; for (; b; b /= 2, a *= a) if (b & 1) c *= a;
return c;
}
template <int P> struct MInt {
int x;
constexpr MInt() : x{} {}
constexpr MInt(i64 x_) : x{norm(x_ % getMod())} {}
static int Mod;
constexpr static int getMod() { return P > 0 ? P : Mod; }
constexpr static void setMod(int Mod_) { Mod = Mod_; }
constexpr int up(int x) const {
if (x < 0) x += getMod();
return x;
}
constexpr int down(int x) const {
if (x >= getMod()) x -= getMod();
return x;
}
constexpr int norm(int x) const {
return up(down(x));
}
constexpr int val() const { return x; }
explicit constexpr operator int() const { return x; }
constexpr MInt operator-() const {
MInt res; res.x = norm(getMod() - x); return res;
}
constexpr MInt inv() const {
assert(x != 0);
return power(*this, getMod() - 2);
}
constexpr MInt &operator+=(MInt rhs) & { return x = down(x + rhs.x), *this; }
constexpr MInt &operator-=(MInt rhs) & { return x = up(x - rhs.x), *this; }
constexpr MInt &operator*=(MInt rhs) & { return x = 1ll * x * rhs.x % getMod(), *this; }
constexpr MInt &operator/=(MInt rhs) & { return *this *= rhs.inv(); }
friend constexpr MInt operator+(MInt lhs, MInt rhs) { return lhs += rhs; }
friend constexpr MInt operator-(MInt lhs, MInt rhs) { return lhs -= rhs; }
friend constexpr MInt operator*(MInt lhs, MInt rhs) { return lhs *= rhs; }
friend constexpr MInt operator/(MInt lhs, MInt rhs) { return lhs /= rhs; }
friend constexpr bool operator==(MInt lhs, MInt rhs) { return lhs.val() == rhs.val(); }
friend constexpr bool operator!=(MInt lhs, MInt rhs) { return lhs.val() != rhs.val(); }
friend constexpr std::istream &operator>>(std::istream &is, MInt &a) {
i64 x = 0; is >> x, a = MInt(x); return is;
}
friend constexpr std::ostream &operator<<(std::ostream &os, const MInt &a) {
return os << a.val();
}
};
template <int P> int MInt<P>::Mod = P;
template <> int MInt<0>::Mod = 998244353;
template <int V, int P> constexpr MInt<P> CInv = MInt<P>(V).inv();
constexpr int P = 1000000007;
using Z = MInt<P>;
void solve() {
int n;
Z p;
std::cin >> n >> p;
if (n == 0) {
std::cout << "0\n";
return;
}
int r = n / 6;
Z ans = Z(n / 2 + 1) * 15;
if (r > 0 && n % 2 == 1) {
Z p1 = 1 - power(1 - p, r);
Z p2 = 1 - power(1 - p, r) - power(1 - p, r - 1) * p * r;
Z ptp = 1 - (1 - p1) * (1 - p2);
ans += ptp * (7 * p1 + 6 * (1 - p1) * p2 + 3 * (1 - p1) * (p1 - p2));
}
std::cout << ans << '\n';
}
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 3700kb
input:
10000 0 105131995 1 117692 2 637385120 3 836440520 4 658724304 5 514051456 6 5451264 7 96052631 8 71936851 9 105586941 10 707337536 11 671801275 12 918938970 13 771170452 14 426363392 15 134193130 16 836236496 17 255916160 18 308620046 19 368680120 20 509918554 21 302946768 22 604853125 23 686238240...
output:
0 15 30 30 45 45 60 966860739 75 5485168 90 498799792 105 261269185 120 590717461 135 357724464 150 794226760 165 889940952 180 841259094 195 233653444 210 689164033 225 360831810 240 627716590 255 192741039 270 728030178 285 797951899 300 703150862 315 377396600 330 484194922 345 119266858 360 5188...
result:
ok 10000 lines