【Educational Codeforces Round 48 (Rated for Div. 2) C】 Vasya And The Mushrooms
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
显然在没有一直往右走然后走到头再往上走一格再往左走到头之前。
肯定是一直在蛇形走位。。
这个蛇形走位的答案贡献可以预处理出来。很容易。
然后蛇形走位之后走到最右再掉头的这个过程也能倒推出来。
考虑sum[i]和sum[i+1]的转移就好
显然sum[i]只是多了a[i]和b[i]两个格子。
考虑它们的贡献就好。
sum[i]表示从i开始一直走到右,然后再走到左的花费。(且i位置作为t=0
(之后只要把i后面的和乘上之前过的时间elapsed+sum[i],那么就变成t=elapsed开始的啦
但是往右走有两种可能。一种是从a[i]开始。另外一种是从b[i]开始。
所以sum得开成两维的。
枚举一下从哪里开始,之后一直往右走再一直往左走就可以了。
注意爆int的问题。
【代码】
#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define rson mid+1,r,rt<<1|1
using namespace std;
const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int N = 3e5;
int n;
int a[2][N+10];
LL right_to_left[2][N+10],sum2[N+10],cur,ans;
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ri(n);
rep1(i,0,1)
rep1(j,1,n)
ri(a[i][j]);
rep2(i,n,1){
sum2[i] = sum2[i+1]+a[0][i]+a[1][i];
}
rep2(i,n,1){
right_to_left[0][i] = right_to_left[0][i+1] + sum2[i+1] + 0*a[0][i] + 1LL*((n-i+1)*2-1)*a[1][i];
right_to_left[1][i] = right_to_left[1][i+1] + sum2[i+1] + 0*a[1][i] + 1LL*((n-i+1)*2-1)*a[0][i];
}
cur = 0;
ans = right_to_left[0][1];
rep1(i,1,n){
if (i&1){
LL time_elapsed = (i-1)*2;
cur+=time_elapsed*a[0][i];
time_elapsed++;
cur+=time_elapsed*a[1][i];
ans = max(ans,1LL*(cur+(time_elapsed+1)*sum2[i+1]+right_to_left[1][i+1]));
}else{
LL time_elapsed = (i-1)*2;
cur+=time_elapsed*a[1][i];
time_elapsed++;
cur+=time_elapsed*a[0][i];
ans = max(ans,1LL*(cur+(time_elapsed+1)*sum2[i+1]+right_to_left[0][i+1]));
}
}
cout<<ans<<endl;
return 0;
}
【Educational Codeforces Round 48 (Rated for Div. 2) C】 Vasya And The Mushrooms的更多相关文章
- 【Educational Codeforces Round 48 (Rated for Div. 2) D】Vasya And The Matrix
[链接] 我是链接,点我呀:) [题意] 告诉你每一行.每一列的异或和. 让你求出一个符合要求的原矩阵. [题解] 显然应该有 a1^a2^....^an = b1^b2^....^bn 也即两边同时 ...
- 【Educational Codeforces Round 53 (Rated for Div. 2) C】Vasya and Robot
[链接] 我是链接,点我呀:) [题意] [题解] 如果|x|+|y|>n 显然.从(0,0)根本就没法到(x,y) 但|x|+|y|<=n还不一定就能到达(x,y) 注意到,你每走一步路 ...
- 【 Educational Codeforces Round 51 (Rated for Div. 2) F】The Shortest Statement
[链接] 我是链接,点我呀:) [题意] [题解] 先处理出来任意一棵树. 然后把不是树上的边处理出来 对于每一条非树边的点(最多21*2个点) 在原图上,做dijkstra 这样就能处理出来这些非树 ...
- 【Educational Codeforces Round 41 (Rated for Div. 2) D】Pair Of Lines
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果点的个数<=3 那么直接输出有解. 否则. 假设1,2最后会在一条直线上,则把这条直线上的点都删掉. 看看剩余的点是否在同 ...
- Educational Codeforces Round 48 (Rated for Div. 2) D 1016D Vasya And The Matrix (构造)
D. Vasya And The Matrix time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Educational Codeforces Round 48 (Rated for Div. 2) CD题解
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...
- Educational Codeforces Round 48 (Rated for Div. 2)
http://codeforces.com/contest/1016 A. 没想到这个也会TLE,太粗心了 B. 暴力就好了,多情况讨论又出错... 思路跟我一样的解法 为什么我做了那么多讨论,原 ...
- Educational Codeforces Round 48 (Rated for Div. 2) B 1016B Segment Occurrences (前缀和)
B. Segment Occurrences time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 【Educational Codeforces Round 38 (Rated for Div. 2)】 Problem A-D 题解
[比赛链接] 点击打开链接 [题解] Problem A Word Correction[字符串] 不用多说了吧,字符串的基本操作 Problem B Run for your prize[贪心] ...
随机推荐
- [Javascript Crocks] Safely Access Object Properties with `prop`
In this lesson, we’ll use a Maybe to safely operate on properties of an object that could be undefin ...
- hdoj1051Wooden Sticks
/*这道题目是先要排序的,依照长度或者重量排都能够. 当长度(重量)同样时就依照重量(长度)排, 从大到小或从小到大都能够! 这里我懂的.没有问题! 排序之后,问题就能够简化,(如果依照长度不等 ...
- Android动态部署五:怎样从插件apk中启动Service
转载请注明出处:http://blog.csdn.net/ximsfei/article/details/51072332 github地址:https://github.com/ximsfei/Dy ...
- ios weak和strong的差别
The difference is that an object will be deallocated as soon as there are no strong pointers to it. ...
- Intellij IDEA社区版打包Maven项目成war包,并部署到tomcat上
转自:https://blog.csdn.net/yums467/article/details/51660683 需求分析 我们利用 Intellij idea社区版IDE开发了一个maven的sp ...
- B - Soldier and Bananas
Problem description A soldier wants to buy w bananas in the shop. He has to pay k dollars for the fi ...
- Spring《七》ApplicationContext
1.国际化支持 getMessage()提供了国际化支持. Bean中必须定义为messageSource. <bean id="messageSource" class=& ...
- 装饰模式(Decorator)C++实现
装饰模式 层层包装,增强功能.这就是装饰模式的要旨!装饰器模式就是基于对象组合的方式,可以很灵活的给对象添加所需要的功能.它把需要装饰的功能放在单独的类中,并让这个类包装它所要装饰的对象. 意图: 动 ...
- WebStorm2018.2 破解 激活
1.进入http://idea.lanyus.com/,如图: 2.下载http://idea.lanyus.com/jar/JetbrainsCrack-3.1-release-enc.jar . ...
- Android Studio ( Linux) 创建模拟器报错
Linux下Android studio创建模拟器最后一步报错 报错:An error occurred while creating the AVD. See idea.log for detail ...