Vasya And The Mushrooms CodeForces - 1016C (前缀和模拟)
大意: 给定2*n的矩阵, 每个格子有权值, 走到一个格子的贡献为之前走的步数*权值, 每个格子只能走一次, 求走完所有格子最大贡献.
沙茶模拟打了一个小时总算打出来了
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head #ifdef ONLINE_JUDGE
const int N = 1e6+10;
#else
const int N = 111;
#endif int n;
int a[2][N];
ll d[2][N], suf[N], s[2][N], b[2][2][N]; int main() {
scanf("%d", &n);
REP(i,1,n) scanf("%d", a[0]+i);
REP(i,1,n) scanf("%d", a[1]+i);
ll now = 0, clk = 0, ans = 0, s1 = 0, s2 = 0;
REP(i,1,n) {
ans += clk*a[now][i], d[now][i] = ans;
++clk, now ^= 1;
ans += clk*a[now][i], d[now][i] = ans;
++clk;
}
PER(i,1,n) suf[i]=suf[i+1]+a[0][i]+a[1][i];
clk = 0;
REP(j,1,n) b[0][0][j]=clk*a[0][j],b[1][1][j]=clk*a[1][j],++clk;
PER(j,1,n) b[0][1][j]=clk*a[1][j],b[1][0][j]=clk*a[0][j],++clk;
REP(i,0,1) PER(j,1,n) s[i][j]=s[i][j+1]+b[i][0][j]+b[i][1][j];
REP(i,0,1) REP(j,1,n) if (j&1^i) {
ans=max(ans, d[i][j-1]+s[i][j]+(j-1)*suf[j]);
}
printf("%lld\n", ans);
}
Vasya And The Mushrooms CodeForces - 1016C (前缀和模拟)的更多相关文章
- Vasya and Beautiful Arrays CodeForces - 354C (数论,枚举)
Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to ...
- Vasya and a Tree CodeForces - 1076E(线段树+dfs)
I - Vasya and a Tree CodeForces - 1076E 其实参考完别人的思路,写完程序交上去,还是没理解啥意思..昨晚再仔细想了想.终于弄明白了(有可能不对 题意是有一棵树n个 ...
- codeforces 1016C - Vasya And The Mushrooms 【构造 + 思维】
题目链接:戳这里 题意:从(1,1)出发,一遍把格子走完,每个格子只能走一次.问怎么走总和最大. 解题思路:画图可知,总共就3种走法的混合. dw: 样例1的走法 up: 样例1反过来的走法 lp: ...
- CodeForces - 1016C Vasya And The Mushrooms
题面在这里! 好久没有体会这种A题的快感了23333 一开始看错了,以为权值是从1开始的,不过这样不要紧,最后把算的答案减去两行数的和就是正确的答案了. 然后发现位于一个角上的时候,我们其实只有两种选 ...
- codeforces C. Vasya And The Mushrooms (思维+模拟)
题意:给定一个2*n的矩形方格,每个格子有一个权值,从(0,0)开始出发,要求遍历完整个网格(不能重复走一个格子),求最大权值和,(权值和是按照step*w累加,step步数从0开始). 转载: 题解 ...
- 【Educational Codeforces Round 48 (Rated for Div. 2) C】 Vasya And The Mushrooms
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然在没有一直往右走然后走到头再往上走一格再往左走到头之前. 肯定是一直在蛇形走位.. 这个蛇形走位的答案贡献可以预处理出来.很容易 ...
- Codeforces Round #427 (Div. 2) Problem C Star sky (Codeforces 835C) - 前缀和
The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinat ...
- Codeforces 612D 前缀和处理区间问题
传送门:http://codeforces.com/problemset/problem/612/D (转载请注明出处谢谢) 题意: 给出数字n和k,n表示接下来将输入n个在x轴上的闭区间[li,ri ...
- CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26
/* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...
随机推荐
- reshape2
require(reshape2)x = data.frame(subject = c("John", "Mary"), tim ...
- SQL中的字母的大小写转换
http://blog.csdn.net/dxb601/article/details/52086830 update 表名 set 字段名a= Lower(字段a) 2.将小写字母转化成大写字母 ...
- Docker Engine SDKs and API 的开发2
Examples using the Docker Engine SDKs and Docker API After you install Docker, you can install the G ...
- try里Response.end()问题
问题 在xxx.aspx.cs中处理异步请求,大致代码如下: 但会发现始终会进catch. 原因 Response.End()会引发ThreadAbortException. 解决方案 使用HttpC ...
- Linux安装python3.7
1.下载与解压 先到python官网: https://www.python.org/downloads/release/python-371/](https://www.python.org/dow ...
- Android CPU耗电量测试
Android CPU耗电量测试 在测试Android app时,不仅仅要关注app的功能,也好关注app的性能指标,cpu.内存.流量.电量等.简单介绍下电量测试中的cpu耗电. 影响耗电的因素 C ...
- 【RFT】【环境配置】Mac
参考地址:http://blog.csdn.net/u010044052/article/details/70858015?utm_source=itdadao&utm_medium=refe ...
- BZOJ 3878 【AHOI2014】 奇怪的计算器
题目链接:奇怪的计算器 如果没有溢出的话,所有的标记都可以在线段树上直接维护,所以一棵线段树就解决问题了. 现在有了溢出,怎么办呢? 发现就算溢出了,各个元素的相对大小关系也是不变的.所以,如果一开始 ...
- 【BZOJ】2734: [HNOI2012]集合选数
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2734 考虑$N=4$的情况: \begin{bmatrix} 1&3 &X ...
- intellij idea 破解教程
首先呼吁:抵制盗版,抵制盗版,抵制盗版 如果只是个人开发学习用,那么下面的教程可能比较适合你了 有两种方法,第一种:Activate--License server,在License server a ...