QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#374851#8305. AcceleratorPetroTarnavskyi#WA 1ms3804kbC++202.5kb2024-04-02 18:51:462024-04-02 18:51:48

Judging History

你现在查看的是最新测评结果

  • [2024-04-02 18:51:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3804kb
  • [2024-04-02 18:51:46]
  • 提交

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, VI(fullMask + 1));
	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, SZ(dp[j]))
			{
				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(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: 3804kb

input:

3
3
1 2 3
1
10
4
5 5 5 5

output:

4.000000000000000
4.000000000000000
4.000000000000000

result:

wrong answer 1st lines differ - expected: '665496247', found: '4.000000000000000'