QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#374857 | #8305. Accelerator | PetroTarnavskyi# | WA | 1ms | 3788kb | C++20 | 2.7kb | 2024-04-02 18:54:57 | 2024-04-02 18:54:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
template<typename T>
void updMax(T& a, T b)
{
a = max(a, b);
}
bool hasBit(int mask, int i)
{
return (mask >> i) & 1;
}
db area(int y, int h1, int h2)
{
if (h1 > h2)
swap(h1, h2);
if (h1 >= y)
return y;
if (h2 <= y)
return (h1 + h2) / 2.0;
return y - (y - h1) * (y - h1) / (2.0 * (h2 - h1));
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(15);
int n, w, h;
cin >> n >> w >> h;
VI a(n + 2);
FOR(i, 1, n + 1)
cin >> a[i];
int m = 2 * w - 1, fullMask = (1 << m) - 1;
vector f(n + 1, vector<db>(1 << m));
VI l(2 * w), r(2 * w);
FOR(i, 1, n + 1)
{
FOR(mask, 0, 1 << m)
{
l.assign(2 * w, max(0, a[i] - h));
r.assign(2 * w, a[i] + h);
FOR(j, 0, m)
{
if (!hasBit(mask, j))
continue;
int k = i - j - 1;
if (k < 1)
continue;
FOR(p, 0, 2 * w)
{
int index = i + p - w;
if (k - w <= index && index < k + w)
{
int& curL = l[p];
int& curR = r[p];
if (a[i] - h <= a[k] - h && a[k] - h <= a[i] + h)
{
curR = min(curR, a[k] - h);
}
if (a[i] - h <= a[k] + h && a[k] + h <= a[i] + h)
{
curL = max(curL, a[k] + h);
}
}
}
}
FOR(p, 0, 2 * w)
{
int index = i + p - w;
if (l[p] < r[p] && index >= 0 && index + 1 < n + 2)
{
f[i][mask] += area(r[p], a[index], a[index + 1]) - area(l[p], a[index], a[index + 1]);
}
}
}
}
vector dp(n + 1, vector<db>(1 << m, -1));
vector ndp(n + 1, vector<db>(1 << m, -1));
dp[0][0] = 0;
FOR(i, 0, n)
{
FOR(j, 0, n + 1)
FOR(mask, 0, 1 << m)
ndp[j][mask] = -1;
FOR(j, 0, n + 1)
{
FOR(mask, 0, 1 << m)
{
if (dp[j][mask] < 0)
continue;
updMax(ndp[j][(2 * mask) & fullMask], dp[j][mask]);
updMax(ndp[j + 1][(2 * mask + 1) & fullMask], dp[j][mask] + f[i + 1][mask]);
}
}
dp = ndp;
FOR(j, 0, n + 1)
{
FOR(mask, 0, 1 << m)
{
if (dp[j][mask] < 0)
continue;
cerr << i + 1 << " " << j << " ";
RFOR(k, m, 0)
{
cerr << hasBit(mask, k);
}
cerr << " " << dp[j][mask] << endl;
}
}
}
FOR(k, 1, n + 1)
{
db ans = 0;
FOR(mask, 0, 1 << m)
{
updMax(ans, dp[k][mask]);
}
cout << ans << "\n";
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3788kb
input:
3 3 1 2 3 1 10 4 5 5 5 5
output:
5.250000000000000 6.000000000000000 6.000000000000000
result:
wrong answer 1st lines differ - expected: '665496247', found: '5.250000000000000'