CodeChef Count Substrings
Count SubstringsProblem code: CSUB
|
All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian.
Given a string S consisting of only 1s and 0s, find the number of substrings which start and end both in 1.
In this problem, a substring is defined as a sequence of continuous characters Si, Si+1, ..., Sj where 1 ≤ i ≤ j ≤ N.
Input
First line contains T, the number of testcases. Each testcase consists of N(the length of string) in one line and string in second line.
Output
For each testcase, print the required answer in one line.
Constraints
- 1 ≤ T ≤ 105
- 1 ≤ N ≤ 105
- Sum of N over all testcases ≤ 105
Example
Input:
2
4
1111
5
10001 Output:
10
3
存在任意两个数 gcd = 1 必然为n , 否则为 -1
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue> using namespace std;
const int N = ;
int n , m , e[N] , ans ;
inline int gcd( int a , int b ) { return b == ? a : gcd(b,a%b); }
int Run() {
scanf("%d",&n);
for( int i = ; i < n ; ++i ) scanf("%d",&e[i]);
sort( e , e + n );
for( int i = ; i < n ; ++i ) if( gcd(e[],e[i]) == ) {
return n;
}
return -;
}
int main()
{
#ifdef LOCAL
freopen("in","r",stdin);
#endif
ios::sync_with_stdio();
int _ , cas = ;
scanf("%d",&_);
while(_--) printf("%d\n",Run());
}
CodeChef Count Substrings的更多相关文章
- 【LeetCode】1180. Count Substrings with Only One Distinct Letter 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 组合数 日期 题目地址:https://leetcod ...
- scau 2015寒假训练
并不是很正规的.每个人自愿参与自愿退出,马哥找题(马哥超nice么么哒). 放假第一周与放假结束前一周 2015-01-26 http://acm.hust.edu.cn/vjudge/contest ...
- nodejs api 中文文档
文档首页 英文版文档 本作品采用知识共享署名-非商业性使用 3.0 未本地化版本许可协议进行许可. Node.js v0.10.18 手册 & 文档 索引 | 在单一页面中浏览 | JSON格 ...
- CF451D Count Good Substrings (DP)
Codeforces Round #258 (Div. 2) Count Good Substrings D. Count Good Substrings time limit per test 2 ...
- [LeetCode] Count Binary Substrings 统计二进制子字符串
Give a string s, count the number of non-empty (contiguous) substrings that have the same number of ...
- [Swift]LeetCode696. 计数二进制子串 | Count Binary Substrings
Give a string s, count the number of non-empty (contiguous) substrings that have the same number of ...
- LeetCode 696 Count Binary Substrings 解题报告
题目要求 Give a string s, count the number of non-empty (contiguous) substrings that have the same numbe ...
- 696. Count Binary Substrings
Give a string s, count the number of non-empty (contiguous) substrings that have the same number of ...
- [LeetCode&Python] Problem 696. Count Binary Substrings
Give a string s, count the number of non-empty (contiguous) substrings that have the same number of ...
随机推荐
- 【记录】Git pull(拉取),push(上传)命令整理(详细)
前言:博主最近在学习git命令,因为git是一个非常好用的分布式版本管理工具,功能比svn强大,与SVN不同点是Git去中心化,每一个分支都是一个中心,并且支持本地仓库存储,像如今很多大公司都用git ...
- 2018-2-13-Windows-10-16251-添加的-api
title author date CreateTime categories Windows 10 16251 添加的 api lindexi 2018-2-13 17:23:3 +0800 201 ...
- python if-else替代三元表达式
python中判断一个数是否是偶数的常规代码: def _compare(data): if data % 2 == 0: return True else: return False # 调用偶数判 ...
- 读书笔记三、pandas之重新索引
- struts2+jsp 遍历 <s:iterator><s:property>
直接把list用request传到jsp页面 <s:iterator var="u" value="#request.users"> <tr& ...
- Ckeditor IE下粘贴word中图片问题
自动导入Word图片,或者粘贴Word内容时自动上传所有的图片,并且最终保留Word样式,这应该是Web编辑器里面最基本的一个需求功能了.一般情况下我们将Word内容粘贴到Web编辑器(富文本编辑器) ...
- 20180704-Java开发环境配置
介绍如何搭建Java开发环境推荐:在Cloud Studio中运行Java程序 Java是一种跨平台的编程语言,想要让你的计算机能够运行Java程序那么就需要安装JRE,而想要开发Java程序,那么就 ...
- Elven Postman
Elven Postman Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- Web 开发中很实用的效果【源码下载】
网页特效下载 引用地址:http://www.yyyweb.com/350.html 超炫的页面切换动画效果 今天我们想与大家分享一组创意的页面切换熊效果集合.我们已经在示例中罗列了一组动画,可以被应 ...
- 牛客网暑期ACM多校训练营(第五场) F - take —— 期望+树状数组+逆元
看到一篇好的博客特意转出来观摩大佬:转:https://blog.csdn.net/greybtfly/article/details/81413526 题目大意:给n个箱子排成一排,从头到尾按顺序依 ...