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 ...
随机推荐
- python if-else替代三元表达式
python中判断一个数是否是偶数的常规代码: def _compare(data): if data % 2 == 0: return True else: return False # 调用偶数判 ...
- 一、模型验证CoreWebApi 管道方式(非过滤器处理)
一.新建.Net Core的MVC项目添加WebApi控制器的方式 using System; using System.Collections.Generic; using System.Linq; ...
- 卷积神经网络 CNN 系列模型阐述
http://www.sohu.com/a/134347664_642762 Lenet,1986年 https://github.com/BVLC/caffe/blob/master/example ...
- vue 概念与使用vue-cli脚手架快速构建项目
vue 定义:是一套构建用户界面的渐进式框架,Vue 采用自底向上增量开发的设计.Vue 的核心库只关注视图层,它不仅易于上手,还便于与第三方库或既有项目整合. 数据渲染机制: 核心: 响应式数据绑定 ...
- tensor与数组转化
import tensorflow as tfimg1 = tf.constant(value=[[[[1],[2],[3],[4]],[[1],[2],[3],[4]],[[1],[2],[3],[ ...
- 通过反射获取方法的参数名称(JDK8以上支持)
方法的参数名,在很多时候我们是需要反射得到的.但是在java8之前,代码编译为class文件后,方法参数的类型是固定的,但参数名称却丢失了,这和动态语言严重依赖参数名称形成了鲜明对比.(java是静态 ...
- 021:自定义path(或url)转换器
1.实现如下需求:用户可以根据articles/list/方式获取文章,其中文章分类是采用如下分类,实例如下: 第一种:获取python分类下的文章:/article/python/ 第二种:获取py ...
- 简单的使用redis
心不慌手不抖我们跟着大哥走 https://blog.csdn.net/zhangcongyi420/article/details/82686702
- ht-7 treeSet特性
TreeSetTreeSet可以对set集合中的元素进行排序,默认按照asic码表的自然顺序排序,之所以treeset能排序是因为底层是二叉树,数据越多越慢,TreeSet是依靠TreeMap来实现的 ...
- Guid--调用Guid.genID();
package com.ufgov.ar.common.util; import java.net.InetAddress; /** * <p> * Title: 产生唯一标识 /** * ...