提交记录 8535


用户 题目 状态 得分 用时 内存 语言 代码长度
lwy noip18a. 【NOIP2018】铺设道路 Accepted 100 79.012 ms 684 KB C++ 1.20 KB
提交时间 评测时间
2019-02-23 18:53:28 2020-08-01 01:20:33
// luogu-judger-enable-o2
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
int d[100100], n;
long long ans;
priority_queue <int, vector<int>, greater<int> > q;
inline int read()
{
	int x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')
		ch = getchar();
	while (ch >= '0' && ch <= '9')
		x = x * 10 + ch - '0', ch = getchar();
	return x;
}
int main()
{
//	freopen("road.in", "r", stdin);
//	freopen("road.out", "w", stdout);
	scanf("%d", &n);
	for (int i = 1;  i <= n; i++)
		d[i] = read();
	while(1)
	{
		bool flag = 1;
		int last = 1;
		for (int i = 1; i <= n + 1; i++)
		{
			if (d[i] == 0 && d[i - 1] == 0 && d[i + 1] == 0)
			{
				last = i + 1;
				continue;
			}
			if (d[i] != 0 && (d[i - 1] == 0 && d[i + 1] == 0))
			{
				ans += d[i];
				d[i] = 0;
				last = i + 1;
				continue;
			}
			if (d[i] != 0) flag = 0, q.push(d[i]);
			if (d[i] == 0 && last != i)
			{
				int del = q.top();
				ans += del;
				for (int j = last; j <= i; j++)
					if (d[j])
					d[j] -= del;
				last = i + 1;
				while(!q.empty())
				q.pop();
			}
		}
		if (flag)
			break;
	}
	printf("%lld", ans);
	return 0;
}//6 4 3 2 5 3 5

CompilationN/AN/ACompile OKScore: N/A

Testcase #136.35 us40 KBAcceptedScore: 10

Testcase #243.72 us40 KBAcceptedScore: 10

Testcase #338.12 us40 KBAcceptedScore: 10

Testcase #438.14 us40 KBAcceptedScore: 10

Testcase #546.32 us40 KBAcceptedScore: 10

Testcase #6116.69 us44 KBAcceptedScore: 10

Testcase #7502.28 us52 KBAcceptedScore: 10

Testcase #84.783 ms112 KBAcceptedScore: 10

Testcase #939.651 ms364 KBAcceptedScore: 10

Testcase #1079.012 ms684 KBAcceptedScore: 10


Judge Duck Online | 评测鸭在线
Server Time: 2024-05-04 14:35:07 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用