QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#545256 | #9220. Bus Analysis | KKT89 | WA | 6ms | 7076kb | C++17 | 4.7kb | 2024-09-03 05:32:49 | 2024-09-03 05:32:49 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }
template <int mod> struct static_modint {
using mint = static_modint;
int x;
static_modint() : x(0) {}
static_modint(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
mint &operator+=(const mint &rhs) {
if ((x += rhs.x) >= mod) x -= mod;
return *this;
}
mint &operator-=(const mint &rhs) {
if ((x += mod - rhs.x) >= mod) x -= mod;
return *this;
}
mint &operator*=(const mint &rhs) {
x = (int)(1LL * x * rhs.x % mod);
return *this;
}
mint &operator/=(const mint &rhs) { return *this = *this * rhs.inv(); }
mint pow(long long n) const {
mint _x = *this, r = 1;
while (n) {
if (n & 1) r *= _x;
_x *= _x;
n >>= 1;
}
return r;
}
mint inv() const { return pow(mod - 2); }
mint operator+() const { return *this; }
mint operator-() const { return mint() - *this; }
friend mint operator+(const mint &lhs, const mint &rhs) { return mint(lhs) += rhs; }
friend mint operator-(const mint &lhs, const mint &rhs) { return mint(lhs) -= rhs; }
friend mint operator*(const mint &lhs, const mint &rhs) { return mint(lhs) *= rhs; }
friend mint operator/(const mint &lhs, const mint &rhs) { return mint(lhs) /= rhs; }
friend bool operator==(const mint &lhs, const mint &rhs) { return lhs.x == rhs.x; }
friend bool operator!=(const mint &lhs, const mint &rhs) { return lhs.x != rhs.x; }
friend ostream &operator<<(ostream &os, const mint &p) { return os << p.x; }
friend istream &operator>>(istream &is, mint &a) {
int64_t t;
is >> t;
a = static_modint<mod>(t);
return (is);
}
};
const unsigned int mod = 1e9 + 7;
using modint = static_modint<mod>;
modint mod_pow(ll n, ll x) { return modint(n).pow(x); }
modint mod_pow(modint n, ll x) { return n.pow(x); }
const int A = 20, B = 75;
// dp[t] = dp[t-B+x] + 3 (0 <= x < i)
// dp[t] = dp[t-B+x] + 2 (i <= x < j)
// dp[t] = dp[t-B+x] + 1 (j <= x < k)
// dp[t] = dp[t-B+x] (k <= x < B)
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> t(n);
for (int i = 0; i < n; ++i) {
cin >> t[i];
}
vector<modint> p2(n, 1);
for (int i = 1; i < n; ++i) {
p2[i] = p2[i - 1] * 2;
}
vector<vector<vector<modint>>> dp(B + 1, vector<vector<modint>>(B + 1, vector<modint>(B + 1)));
dp[0][0][0] = 1;
modint res = 0;
int pre = 0;
for (int m = 0; m < n; ++m) {
int add = t[m] - pre;
vector<vector<vector<modint>>> ndp(B + 1, vector<vector<modint>>(B + 1, vector<modint>(B + 1)));
for (int i = 0; i <= B; ++i) {
for (int j = 0; j <= B; ++j) {
for (int k = 0; k <= B; ++k) {
if (dp[i][j][k] == 0) continue;
int a = max(0, i - add);
int b = max(0, i - add);
int c = max(0, i - add);
// 使わない場合
ndp[a][b][c] += dp[a][b][c];
// 使う場合
{
vector<int> cost(76);
for (int l = 0; l < cost.size(); ++l) {
if (l < a) cost[l] = -3;
else if (l < b) cost[l] = -2;
else if (l < c) cost[l] = -1;
else cost[l] = 0;
}
cost.back() = 1;
for (int l = 0; l < cost.size(); ++l) {
if (l - A >= 0) cost[l] = min(cost[l], cost[l - A] + 1);
if (l - B >= 0) cost[l] = min(cost[l], cost[l - B] + 3);
}
if (cost.back() >= 1) res += dp[i][j][k] * p2[n - 1 - m] * cost.back();
int na = 0, nb = 0, nc = 0;
for (int l = 0; l < cost.size(); ++l) {
if (cost[l] <= -3) na += 1, nb += 1, nc += 1;
else if (cost[l] <= -2) nb += 1, nc += 1;
else if (cost[l] <= -1) nc += 1;
}
dp[na][nb][nc] += dp[a][b][c];
}
}
}
}
pre = t[m];
swap(dp, ndp);
}
cout << res * 2 << endl;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 7076kb
input:
3 1 8 20
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: -100
Wrong Answer
time: 6ms
memory: 7044kb
input:
5 25 45 65 85 1000000000
output:
62
result:
wrong answer 1st numbers differ - expected: '156', found: '62'