QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#281989#323. HillsA_programmer0 1ms3728kbC++141.3kb2023-12-11 09:15:432023-12-11 09:15:43

Judging History

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

  • [2023-12-11 09:15:43]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3728kb
  • [2023-12-11 09:15:43]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int dp[2505][5], dp_n[2505][5];
int a[5005], ans[2505], m;

int judge(int i, int op, int k)
{
	if ((a[i] > a[i - 1] || op == 3 || op == 4) && (a[i] > a[i + 1] || op == 1 || op == 4) && op != 2) k++;
	return min(k, m);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); 
	
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	a[0] = a[n + 1] = -1e9;
	
	m = (n + 1) / 2;
	memset(dp, 0x3f, sizeof(dp));
	dp[0][0] = 0;
	for (int i = 1; i <= n; i++)
	{
		memset(dp_n, 0x3f, sizeof(dp_n));
		
		int dat = max(0, a[i] - min(a[i - 1], a[i + 1]) + 1);
		for (int k = 0; k <= (i + 1) / 2; k++)
		{
			dp_n[judge(i, 0, k)][0] = min(dp_n[judge(i, 0, k)][0], min(dp[k][0], dp[k][3]));
			dp_n[judge(i, 1, k)][1] = min(dp_n[judge(i, 1, k)][1], min(dp[k][0], dp[k][3]));
			dp_n[judge(i, 2, k)][2] = min(dp_n[judge(i, 2, k)][2], min(dp[k][1], dp[k][4]) + dat);
			dp_n[judge(i, 3, k)][3] = min(dp_n[judge(i, 3, k)][3], dp[k][2]);
			dp_n[judge(i, 4, k)][4] = min(dp_n[judge(i, 4, k)][4], dp[k][2]);
		}
		memcpy(dp, dp_n, sizeof(dp_n));
	}
	
	for (int k = 1; k <= m; k++) ans[k] = min(dp[k][0], dp[k][3]);
	for (int k = m - 1; k; k--) ans[k] = min(ans[k], ans[k + 1]);
	for (int k = 1; k <= m; k++) cout << ans[k] << " ";
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 1ms
memory: 3728kb

input:

3
1 2 4

output:

0 2 

result:

ok 2 number(s): "0 2"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3500kb

input:

3
3 2 1

output:

0 2 

result:

ok 2 number(s): "0 2"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3704kb

input:

3
1 2 1

output:

0 2 

result:

ok 2 number(s): "0 2"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3440kb

input:

3
3 3 3

output:

1 1 

result:

ok 2 number(s): "1 1"

Test #5:

score: -7
Wrong Answer
time: 1ms
memory: 3552kb

input:

3
50 80 80

output:

31 31 

result:

wrong answer 1st numbers differ - expected: '1', found: '31'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%