QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#530547 | #9220. Bus Analysis | ucup-team896# | TL | 19ms | 10444kb | C++20 | 3.5kb | 2024-08-24 16:31:59 | 2024-08-24 16:32:00 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
template<class T>inline void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T>inline void chkmx(T &x, T y) { if (y > x) x = y; }
using namespace std;
template <int P>
class mod_int {
using Z = mod_int;
private:
static int mo(int x) { return x < 0 ? x + P : x; }
public:
int x;
int val() const { return x; }
mod_int() : x(0) {}
template <class T>
mod_int(const T &x_) : x(x_ >= 0 && x_ < P ? static_cast<int>(x_) : mo(static_cast<int>(x_ % P))) {}
bool operator==(const Z &rhs) const { return x == rhs.x; }
bool operator!=(const Z &rhs) const { return x != rhs.x; }
Z operator-() const { return Z(x ? P - x : 0); }
Z pow(long long k) const {
Z res = 1, t = *this;
while (k) {
if (k & 1) res *= t;
if (k >>= 1) t *= t;
}
return res;
}
Z &operator++() {
x < P - 1 ? ++x : x = 0;
return *this;
}
Z &operator--() {
x ? --x : x = P - 1;
return *this;
}
Z operator++(int) {
Z ret = x;
x < P - 1 ? ++x : x = 0;
return ret;
}
Z operator--(int) {
Z ret = x;
x ? --x : x = P - 1;
return ret;
}
Z inv() const { return pow(P - 2); }
Z &operator+=(const Z &rhs) {
(x += rhs.x) >= P && (x -= P);
return *this;
}
Z &operator-=(const Z &rhs) {
(x -= rhs.x) < 0 && (x += P);
return *this;
}
Z &operator*=(const Z &rhs) {
x = 1ULL * x * rhs.x % P;
return *this;
}
Z &operator/=(const Z &rhs) { return *this *= rhs.inv(); }
#define setO(T, o) \
friend T operator o(const Z &lhs, const Z &rhs) {\
Z res = lhs; \
return res o## = rhs; \
}
setO(Z, +) setO(Z, -) setO(Z, *) setO(Z, /)
#undef setO
};
const int P = 1e9 + 7;
using Z = mod_int<P>;
const int maxn = 1010;
int n, a[maxn];
Z f[75][75][75], g[75][75][75];
Z tf[75][75][75], tg[75][75][75];
int main() {
cin.tie(nullptr) -> ios::sync_with_stdio(false);
cin >> n;
rep (i, 1, n) cin >> a[i];
f[0][0][0] = 1, f[19][19][74] = 1, g[19][19][74] = 1;
rep (i, 2, n) {
rep (x, 0, 74) rep (y, x, 74) rep (z, y, 74) {
tg[x][y][z] = g[x][y][z], tf[x][y][z] = f[x][y][z];
f[x][y][z] = g[x][y][z] = 0;
}
rep (x, 0, 74) rep (y, x, 74) rep (z, y, 74) {
int d = a[i] - a[i - 1];
f[max(0, x - d)][max(0, y - d)][max(0, z - d)] += tf[x][y][z];
g[max(0, x - d)][max(0, y - d)][max(0, z - d)] += tg[x][y][z];
vector<pii> vec;
if (x - d >= 0) vec.emplace_back(x - d, 0);
if (y - d >= 0) vec.emplace_back(y - d, 1);
if (z - d >= 0) vec.emplace_back(z - d, 2);
vec.emplace_back(74, 3), vec.emplace_back(19, 1);
int mn = 3, mx[3];
for (auto [x, y] : vec) chkmn(mn, y);
rep (i, 0, 2) mx[i] = 0;
for (auto [x, y] : vec) if (y - mn < 3) chkmx(mx[y - mn], x);
rep (i, 1, 2) chkmx(mx[i], mx[i - 1]);
f[mx[0]][mx[1]][mx[2]] += tf[x][y][z];
g[mx[0]][mx[1]][mx[2]] += tg[x][y][z] + mn * tf[x][y][z];
}
}
Z ans = 0;
rep (i, 0, 74) rep (j, 0, 74) rep (k, 0, 74) ans += g[i][j][k];
cout << (ans * 2).val() << '\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 8ms
memory: 10152kb
input:
3 1 8 20
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 19ms
memory: 10444kb
input:
5 25 45 65 85 1000000000
output:
156
result:
ok 1 number(s): "156"
Test #3:
score: -100
Time Limit Exceeded
input:
1000 2 7 9 12 14 17 18 21 22 28 29 33 34 35 37 38 44 45 46 50 58 59 63 66 71 72 75 76 77 78 80 81 83 84 87 92 100 101 107 108 109 112 114 116 118 123 124 131 142 143 144 145 148 150 151 152 153 155 157 158 165 167 168 169 171 176 182 185 190 192 198 202 204 205 212 213 223 224 225 226 229 231 240 24...