Codeforces Educational Codeforces Round 31
来源:互联网 发布:sqlserver 并发数 编辑:程序博客网 时间:2024/06/06 04:10
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.
For example:
- If x = 6 and the crossword is 111011, then its encoding is an array {3, 2};
- If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1};
- If x = 5 and the crossword is 11111, then its encoding is an array {5};
- If x = 5 and the crossword is 00000, then its encoding is an empty array.
Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
The first line contains two integer numbers n and x (1 ≤ n ≤ 100000, 1 ≤ x ≤ 109) — the number of elements in the encoding and the length of the crossword Mishka picked.
The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 10000) — the encoding.
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
2 41 3
NO
3 103 3 2
YES
2 101 3
NO
题意:有一个长度为x的01串,其中含有n个连续1子串,每个连续1子串中1的个数为ai,问是否只存在一种情况使其成立
思路:只有一种情况时就是在相邻两个连续1子串中只能含有一个0,只有一个连续1子串则整个串中不能含有0
#include<iostream>#include<string.h>#include<stdio.h>using namespace std;#define LL long longint main(){ LL n,x,a,sum = 0; scanf("%lld%lld",&n,&x); for(int i=1;i<=n;i++){ scanf("%lld",&a); sum+=a; if(i!=n) sum++; } if(sum==x) printf("YES\n"); else printf("NO\n"); return 0;}
- Codeforces Educational Codeforces Round 31
- Codeforces Educational Codeforces Round 31
- Codeforces Educational Codeforces Round 31
- Codeforces Educational Codeforces Round 31
- Educational Codeforces Round 31
- Educational Codeforces Round 31
- Educational Codeforces Round 31
- Educational Codeforces Round 31
- Educational Codeforces Round 31 题解
- 【CODEFORCES】 Educational Codeforces Round 1
- Codeforces Educational Codeforces Round 5
- Codeforces Educational Codeforces Round 22
- Codeforces Educational Codeforces Round 27
- Codeforces Educational Codeforces Round 27
- Codeforces Educational Codeforces Round 27
- Codeforces Educational Codeforces Round 27
- Educational Codeforces Round 1
- Educational Codeforces Round 2
- 总结
- 网络端口号大全
- Java中去除字符串中所有空格的几种方法
- 微信小程序 wx.request wepy 简单封装
- 递归
- Codeforces Educational Codeforces Round 31
- 简单日期类(文件)
- Mybatis 框架 3
- 第一次初赛
- Java3+1种修饰符
- 蓝桥杯练习题 字母图形 java实现
- 擦除效果
- OSI七层与TCP/IP五层网络架构
- 清北day1(cubicp)