题目链接

A. Tanya and Stairways

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from 11 to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains 33 steps, and the second contains 44 steps, she will pronounce the numbers 1,2,3,1,2,3,41,2,3,1,2,3,4.

You are given all the numbers pronounced by Tanya. How many stairways did she climb? Also, output the number of steps in each stairway.

The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.

Input

The first line contains nn (1≤n≤10001≤n≤1000) — the total number of numbers pronounced by Tanya.

The second line contains integers a1,a2,…,ana1,a2,…,an (1≤ai≤10001≤ai≤1000) — all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway with xx steps, she will pronounce the numbers 1,2,…,x1,2,…,x in that order.

The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.

Output

In the first line, output tt — the number of stairways that Tanya climbed. In the second line, output tt numbers — the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.

Examples

input

Copy

7
1 2 3 1 2 3 4

output

Copy

2
3 4 

input

Copy

4
1 1 1 1

output

Copy

4
1 1 1 1 

input

Copy

5
1 2 3 4 5

output

Copy

1
5 

input

Copy

5
1 2 1 2 1

output

Copy

3
2 2 1 

代码实现:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
using namespace std;
const double eps = 1e-8;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN=5010;
const int MAXM=100010;
const int M=50010;
int main()
{int n;while(scanf("%d",&n)!=EOF){int a[1010];for(int i=1;i<=n;i++)scanf("%d",&a[i]);int b[1010],j=0;int sum=1;memset(b,0,sizeof(b));for(int i=1;i<n;i++){if(a[i+1]>a[i]){b[sum]++;}elsesum++;}cout<<sum<<endl;for(int i=1;i<sum;i++)cout<<b[i]+1<<" ";cout<<b[sum]+1<<endl;}return 0;
}

CodeForces - 1005A . Tanya and Stairways相关推荐

  1. CF1005A Tanya and Stairways

    题目描述 Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a s ...

  2. Codeforces Round #496 (Div. 3)【未完结】

    2022.3.5 题目地址:https://codeforces.com/contest/1005 目录 A. Tanya and Stairways[找规律] B. Delete from the ...

  3. 基础算法 —— 模拟思维

    [概述] 模拟,是根据实际问题建立模型,模拟实际按程序走一遍,最终求出答案. 思维,则是与逻辑思维有关,其需要针对题意.数据范围等抽丝剥茧抽离出有用的信息,从而得出一个结果. 对于一般的模拟,直接根据 ...

  4. 婚礼请帖_第一次在线婚礼发生在1876年

    婚礼请帖 重点(Top highlight) As the Covid-19 pandemic wears on, more and more of life has moved online - s ...

  5. Codeforces Round #324 (Div. 2) B. Kolya and Tanya 快速幂

    B. Kolya and Tanya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pro ...

  6. Codeforces Round #324 (Div. 2) B. Kolya and Tanya

    思路:因为题目说只要存在组ai?+?ai?+?n?+?ai?+?2n?≠?6就令人满意,也就是不满意的情况就是所有ai?+?ai?+?n?+?ai?+?2n?都等于6 那就用所有的情况减去不满意的情况 ...

  7. Codeforces Round #540 (Div. 3) A,B,C,D2,E,F1

    A. Water Buying 链接:http://codeforces.com/contest/1118/problem/A 实现代码: #include<bits/stdc++.h> ...

  8. Codeforces Round #540 (Div. 3)(部分题解)

    链接:http://codeforces.com/contest/1118 来源:Codeforces 文章目录 A. Water Buying B. Tanya and Candies(前缀和) D ...

  9. Codeforces Round #346 (Div. 2)

    A - Round House 题意:长度为n个环.起始位置是a,然后给出b,b是正数代表顺时针跑b个单位.b是负数代表逆时针跑b个单位. 思路:基础数学题目吧. PS:对于C++和G++编译器而言 ...

最新文章

  1. php 工资 2018,2018年我国公务员级别工资标准
  2. 转eclipse如何修改dynamic web module version .
  3. Flutter开发之ListView使用第三方pull_to_refresh加载更多(36)
  4. RuntimeError: Expected object of backend CUDA but got backend CPU for argument #4 'mat1'
  5. Cuckoo hash算法分析——其根本思想和bloom filter一致 增加hash函数来解决碰撞 节省了空间但代价是查找次数增加...
  6. Android x86 下运行纯ARM版APP
  7. C# 发送消息SendKeys、SendMessage、keybd_event的用法
  8. C# list删除 另外list里面的元素_在Python 中 List 操作 9种例子详细了解
  9. c语言 统计数量用count_请问c语言当中,如何统计数字各自出现的次数
  10. ubuntu grub 操作
  11. javascript 创建ajax函数 四部曲
  12. 手机麦克风结构原理图_麦克风的分类和工作原理
  13. 2022深圳杯/东三省数学建模ABCD题 赛题分析解题方案
  14. R语言使用sort函数对向量数据进行排序、默认从小到大升序排序、设置decreasing为真进行降序排序
  15. h5策划书_DIYH5|3.12世界睡眠日H5策划方案
  16. 基于uniapp开发app,省市区联动
  17. 怎样用XMind 8将思维导图导出为Excel文件
  18. android打败苹果,苹果iOS打败安卓的另一面:配件多于Android
  19. asp.net core ABP模板本地化设置
  20. 实现对 2:3 或者3:2的图片进行1:1裁剪

热门文章

  1. PMP第三章:项目经理的角色
  2. 异步传输模式 Asynchronous Transfer Mode
  3. 深度学习-聊天机器人
  4. 计算机设计大赛应用软件组,组一览表(计算机设计大赛).pdf
  5. 阿里云的这群疯子--深度好文请仔细看完
  6. centos7 无网络 安装oracle 脚本静默安装
  7. 跳表在Java中的实现
  8. 协议确认机制TACK的通俗解析
  9. log4j2设置控制台日志打印颜色
  10. 途牛原创|基于EAV模型的运营系统架构实践