大意: 给定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 (前缀和模拟)的更多相关文章

  1. Vasya and Beautiful Arrays CodeForces - 354C (数论,枚举)

    Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to ...

  2. Vasya and a Tree CodeForces - 1076E(线段树+dfs)

    I - Vasya and a Tree CodeForces - 1076E 其实参考完别人的思路,写完程序交上去,还是没理解啥意思..昨晚再仔细想了想.终于弄明白了(有可能不对 题意是有一棵树n个 ...

  3. codeforces 1016C - Vasya And The Mushrooms 【构造 + 思维】

    题目链接:戳这里 题意:从(1,1)出发,一遍把格子走完,每个格子只能走一次.问怎么走总和最大. 解题思路:画图可知,总共就3种走法的混合. dw: 样例1的走法 up: 样例1反过来的走法 lp: ...

  4. CodeForces - 1016C Vasya And The Mushrooms

    题面在这里! 好久没有体会这种A题的快感了23333 一开始看错了,以为权值是从1开始的,不过这样不要紧,最后把算的答案减去两行数的和就是正确的答案了. 然后发现位于一个角上的时候,我们其实只有两种选 ...

  5. codeforces C. Vasya And The Mushrooms (思维+模拟)

    题意:给定一个2*n的矩形方格,每个格子有一个权值,从(0,0)开始出发,要求遍历完整个网格(不能重复走一个格子),求最大权值和,(权值和是按照step*w累加,step步数从0开始). 转载: 题解 ...

  6. 【Educational Codeforces Round 48 (Rated for Div. 2) C】 Vasya And The Mushrooms

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然在没有一直往右走然后走到头再往上走一格再往左走到头之前. 肯定是一直在蛇形走位.. 这个蛇形走位的答案贡献可以预处理出来.很容易 ...

  7. 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 ...

  8. Codeforces 612D 前缀和处理区间问题

    传送门:http://codeforces.com/problemset/problem/612/D (转载请注明出处谢谢) 题意: 给出数字n和k,n表示接下来将输入n个在x轴上的闭区间[li,ri ...

  9. CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26

    /* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...

随机推荐

  1. win10安装Zookeeper3.4.12

    为了方便在本地开发环境进行调试,希望在win10环境中安装一个zookeeper 安装: 下载: 下载最新的stable版 zookeeper-3.4.12.tar.gz 配置环境变量: ZOOKEE ...

  2. 好用的js模板

    组织form下的 json对象 $.fn.serializeObject = function() { var o = {"unique_id":new Date().getTim ...

  3. P1494 [国家集训队]小Z的袜子(莫队算法)

    莫队板子 代码 #include <cstdio> #include <algorithm> #include <cstring> #include <cma ...

  4. .NET控件集ComponentOne 2018V3发布:新增图表动画及迷你图

    “通过使用 ComponentOne .NET控件产品,实现了兼具 BS 架构灵活性与 CS 架构的客户体验.丰富的控件满足了项目中的各种特殊需求,使得开发的精力可以专注于业务逻辑,为团队节省了时间. ...

  5. POJ 3693 Maximum repetition substring(连续重复子串)

    http://poj.org/problem?id=3693 题意:给定一个字符串,求重复次数最多的连续重复子串. 思路: 这道题确实是搞了很久,首先枚举连续子串的长度L,那么子串肯定包含了r[k], ...

  6. JavaScript深入

    BOM(浏览器对象模型)——与浏览器对话: Window对象(代表浏览器的窗口——不包括工具栏.滚动条): //所有全局对象.全局函数,均自动成为window对象的成员(document属于浏览器,所 ...

  7. _itemmod_refresh

    -- 随机FM刷新设置-- 小技巧:很多服所说的装备鉴定效果可以通过这个实现,也可以对物品重新生成新的附魔--详细解说一下鉴定系统如何实现--1首先在_itemmod_enchant_groups中添 ...

  8. BaseEditor

    using UnityEngine;using System.Collections.Generic;using UnityEditor;using System.Text;using System. ...

  9. Codeforces 769D k-Интересные пары чисел

    题目链接:http://codeforces.com/contest/769/problem/D 搜索题 考虑这些数的值域较小,直接${O(2^{k})}$次方枚举每个数字二进制位上是否改变,剪枝一下 ...

  10. python redis 操作

    1.String 操作 redis中的String在在内存中按照一个name对应一个value来存储 set() #在Redis中设置值,默认不存在则创建,存在则修改 r.set('name', 'z ...