[codeforces 1321B] Journey Planning hack来得太突然

Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round)   比赛人数5638

[codeforces 1321B] Journey Planning   hack来得太突然

总目录详见https://blog.csdn.net/mrcrack/article/details/103564004

在线测评地址https://codeforces.ml/contest/1321/problem/B

ProblemLangVerdictTimeMemory
B - Journey Planning GNU C++11Accepted77 ms2200 KB

绝杀,最后两分钟,被hack掉,瞬间掉了1000多名,心中顿时一沉,该题几乎没有挽回的余地。

此时正好有另一题刚编好,顾不得被hack的B题了,先将手上刚编好的题,进行样例测试,测试之后,看了时间,还有50s,提交AC,瞬间又提升了1000多名,不过回不到原来的位置了。太惊险了。心里稍稍有了好转。

此时的感觉,宛如做过山车。

言归正传,讲一讲,比赛时,如何想出该题。

手模了样例,能找出结果,但算法的时间复杂度是O(n^2),用了些高级数据结构,发现无法进一步的优化。

重新读题,目光聚焦在公式ci+1−ci=bci+1−bci,想着从公式出发,进行处理.

但是,人是很奇怪的动物,很难,马上就想到答案。

大家可以看到,笔者第一直觉,想到ci+1+bci=bci+1+ci显然是做不出,又手模了几分种,突然想到

bci+1-ci+1=bci-ci此题算法瞬间出来,读者若还看不懂,请看样例模拟

Input1:
6
10 7 1 9 10 15
Output1:
26

c    1  2 3  4 5  6
b    10 7 1  9 10 15
b-c  9  5 -2 5 5  9

可选两种情况
c    1  6
b    10 15
b-c  9  9
b的和是10+15=25

c    2 4 5
b    7 9 10
b-c  5 5 5
b的和是7+9+10=26选最大的,此种情况对应答案
Input2:
7
8 9 26 11 12 29 14
Output2:
55

c    1 2 3  4  5  6  7
b    8 9 26 11 12 29 14
b-c  7 7 23 7  7  23 7
可选两种情况
c    1 2 4  5  7
b    8 9 11 12 14
b-c  7 7 7  7  7
b的和是8+9+11+12+14=54

c    3  6
b    26 29
b-c  23 23
b的和是26+29=55选最大的,此种情况对应答案

少了此行判定 b[n+1].delta=400000;//only lost this line//be hacked;//b[n+1].delta==b[n].delta==0 hack 被hack,

hack的时间点还选在离比赛结束不到2分钟,虽有不服,但只能接受。

以下为AC代码。

#include <cstdio>
#include <algorithm>
#define maxn 200010
#define LL long long
using namespace std;
struct node{
	int seq,v,delta;
}b[maxn];
int cmp(node a,node b){
	return a.delta<b.delta;
}
int main(){
	int n,i;
	LL ans=0,tmp=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&b[i].v),b[i].seq=i,b[i].delta=b[i].v-b[i].seq;
	sort(b+1,b+1+n,cmp),ans=tmp=b[1].v;
	b[n+1].delta=400000;//only lost this line//be hacked;//b[n+1].delta==b[n].delta==0 hack
	for(i=2;i<=n+1;i++)
		if(b[i].delta==b[i-1].delta)tmp+=b[i].v;
		else{
			if(ans<tmp)ans=tmp;
			tmp=b[i].v;
		}
	printf("%lld\n",ans);
	return 0;
}

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值