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( ...
随机推荐
- 【server.properties】kafka服务设置
每个kafka broker中配置文件server.properties默认必须配置的属性如下: broker.id=0 num.network.threads=2 num.io.threads=8 ...
- 集合00_Java集合框架
集合类概述 1.继承树 2.集合和数组 区别如下: 数组可以存储基本数据类型,也可以存储引用类型:而集合只能存储引用类型(比如存储int,它会自动装箱成Integer) 数组长度固定,集合长度可变 3 ...
- [小问题笔记(九)] SQL语句Not IN 效率低,用 NOT EXISTS试试
项目中遇到这么个情况: t1表 和 t2表 都是150w条数据,600M的样子,都不算大. 但是这样一句查询 ↓ select * from t1 where phone not in (selec ...
- [从零开始搭网站四]CentOS配置Tomcat
点击下面连接查看从零开始搭网站全系列 从零开始搭网站 上一章带大家配置了JDK,那么现在就要来配置Tomcat容器了. 1:去 http://tomcat.apache.org/download-90 ...
- 【Django】【三】模型
[基本数据访问] 1. models.py写模型 2. 数据库迁移 guest> python manage.py makemigrations sign guest> python ma ...
- SSH KEY 设置 目录在open ~ 根目录下的.ssh 里面
当我们从github或者gitlab上clone项目或者参与项目时,需要证明我们的身份.github.gitlab支持使用SSH协议进行免密登录,而SSH协议采用了RSA算法保证了登录的安全性.我们要 ...
- Python统计list中各个元素出现的次数
来自:天蝎圣诞结 利用Python字典统计 利用Python的collection包下Counter类统计 利用Python的pandas包下的value_counts类统计 字典统计 a = [1, ...
- 将本地项目上传到gitlab下
转载自: https://blog.csdn.net/litianxiang_kaola/article/details/74075151 1.安装git https://git-scm.com ...
- ionic+微信js-sdk集成初步融合,在子路由页引入js操作dom节点
.controller('yaoheCtrl',['$scope',function ($scope) { $scope.$watch('$viewContentLoaded',function(ev ...
- 字符串、字节数组、流之间的相互转换以及文件MD5的计算
using System; using System.IO; using System.Security.Cryptography; using System.Text; namespace myMe ...