CF1130E Wrong Answer
Posted huangchenyan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF1130E Wrong Answer相关的知识,希望对你有一定的参考价值。
构造题+数学
题意是要求一个序列中最大的∑(i>=l且i<=r) (r-l+1)*a[i]的值,题目给出代码,要你hack这份代码,使他的答案与正确答案相差k
function find_answer(n, a)
# Assumes n is an integer between 1 and 2000, inclusive
# Assumes a is a list containing n integers: a[0], a[1], ..., a[n-1]
res = 0
cur = 0
k = -1
for i = 0 to i = n-1
cur = cur + a[i]
if cur < 0
cur = 0
k = i
res = max(res, (i-k)*cur)
return res
考虑在第一个数放一个负数-1,之后的1999个数之和为sum,
则他代码的答案为 sum*1999
正确答案为 (sum-1)*2000
所以 (sum-1)*2000-sum*1999=k
化简得 sum=k+2000
之后将sum均分个之后的1999个数即可
#include <bits/stdc++.h> using namespace std; int k,sum; int main() { scanf("%d",&k); sum=k+2000; printf("2000 "); int t,h; t=sum/1998; h=sum-1998*t; printf("-1 "); for (int i=1;i<=1998;i++) printf("%d ",t); printf("%d ",h); }
以上是关于CF1130E Wrong Answer的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) F2. Wrong Answer on tes