AGC024C Sequence Growing Easy
题目大意
你开始有一个序列x
它所有项都是0
你有一个操作:x[i]=x[i-1]+1
问你至少几次操作可以让x序列变为给定的a序列
分析
老年人完全不会这种脑子题/kk........
我们定义b[i]=i-a[i]
所以对于一个连续的上升子序列它的b是相等的
每次取一段想的b序列中最大的a[i]累加即可
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define int long long
int a[],b[],n,m,ans;
signed main(){
int i,j,k;
scanf("%lld",&n);
for(i=;i<=n;i++){
scanf("%lld",&a[i]);
b[i]=i-a[i];
if(a[i]-a[i-]>||a[i]>=i){
puts("-1");
return ;
}
}
for(i=n;i>;i--){
if(i!=n&&b[i]==b[i+])continue;
ans+=a[i];
}
cout<<ans<<"\n";
return ;
}
AGC024C Sequence Growing Easy的更多相关文章
- AtCoder - 3962 Sequence Growing Hard
Problem Statement Find the number of the possible tuples of sequences (A0,A1,…,AN) that satisfy all ...
- [AtCoder Grand Contest 024 Problem E]Sequence Growing Hard
题目大意:考虑 N +1 个数组 {A0,A1,…,AN}.其中 Ai 的长度是 i,Ai 内的所有数字都在 1 到 K 之间. Ai−1 是 Ai 的子序列,即 Ai 删一个数字可以得到 Ai−1. ...
- AGC024E Sequence Growing Hard
题意 给出\(n\),\(m\),\(mu\),问有多少个序列组\((A_0,A_1,\dots,A_n)\)满足: 序列\(Ai\)的长度恰好为\(i\) 所有元素均在\([1,m]\) \(A_{ ...
- Atcoder Grand Contest 024 E - Sequence Growing Hard(dp+思维)
题目传送门 典型的 Atcoder 风格的计数 dp. 题目可以转化为每次在序列中插入一个 \([1,k]\) 的数,共操作 \(n\) 次,满足后一个序列的字典序严格大于前一个序列,问有多少种操作序 ...
- 【AtCoder】AGC024
A - Fairness 如果奇数次是b - a 否则是a - b #include <bits/stdc++.h> #define fi first #define se second ...
- HDU6205 Coprime Sequence 2017-05-07 18:56 36人阅读 评论(0) 收藏
Coprime Sequence Time Limit: 2000/1000 MS (Ja ...
- Coprime Sequence(前后缀GCD)
Description Do you know what is called ``Coprime Sequence''? That is a sequence consists of $n$ posi ...
- coprime Sequence
Do you know what is called ``Coprime Sequence''? That is a sequence consists of nn positive integers ...
- HDU - 6025 Coprime Sequence(gcd+前缀后缀)
Do you know what is called ``Coprime Sequence''? That is a sequence consists of nnpositive integers, ...
随机推荐
- java Iterator Iterable Collection AbstractCollection Map关系
java.lang Interface Iterable<T> 实现该接口就可以使用for-each循环. java.util Interface Iterator<E> ...
- 在SSIS 的 64 位版本中不支持 Excel 连接管理器[转]
Microsoft sql server 2008 R2——> SQL SERVER Business Intelligence Development Studio 使用EXCEL数据源或目标 ...
- Linux 查看日志文件
1. tail命令:从文本文件的尾部开始查看,用于显示文本文件的末尾几行 tail -n filename 指定需要显示多少行 tail -f filename 实时 ...
- CSRF verification failed. Request aborted.错误解决办法
在Django项目的页面,提交form表单POST请求时,会出现报错:CSRF verification failed. Request aborted. 需要在form表单中加:{% csrf_to ...
- DelayQueue详解
一.DelayQueue是什么 DelayQueue是一个无界的BlockingQueue,用于放置实现了Delayed接口的对象,其中的对象只能在其到期时才能从队列中取走.这种队列是有序的,即队头对 ...
- 使用Webpack的代码分离实现Vue懒加载(译文)
当一个Vue的项目体积变得十分庞大的时候,使用Webpack的代码分离功能将Vue Components,routes或Vuex的代码进行分离并按需加载,会极大的提高App的首屏加载速度. 在Vue的 ...
- SQL 常用语句(一)
--SQL 语句为表添加字段并设置默认值 alter table TableName add ColumnName int --字段类型 not null --是否为空 --默认值 --SQL 语句为 ...
- SSH简单Demo
web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="3 ...
- Python之路-pandas包的详解与使用
什么是pandas pandas是一种Python数据分析的利器,是一个开源的数据分析包,最初是应用于金融数据分析工具而开发出来的,因此pandas为时间序列分析提供了很好的支持.pandas是PyD ...
- 行人重识别(ReID) ——基于Person_reID_baseline_pytorch修改业务流程
下载Person_reID_baseline_pytorch地址:https://github.com/layumi/Person_reID_baseline_pytorch/tree/master/ ...