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 ...
随机推荐
- PyQt5+qtdesigner开发环境配置
1.PyQt5安装 pip install PyQt5 2.qtdesigner安装 本来直接用pip install PyQt5-tools安装的,但是网速下的慢,中间还断了几次,在网上找到一个稳定 ...
- Sass:@at-root
@at-root 从字面上解释就是跳出根元素.当你选择器嵌套多层之后,想让某个选择器跳出,此时就可以使用 @at-root.来看一个简单的示例: .a { color: red; .b { color ...
- java类实现序列化的方法?collection框架中实现什么样的接口
- ThreadPoolExecutor线程池原理
参考: https://www.cnblogs.com/liuzhihu/p/8177371.html
- Task4.文本表示:从one-hot到word2vec
参考:https://blog.csdn.net/wxyangid/article/details/80209156 1.one-hot编码 中文名叫独热编码.一位有效编码.方法是使用N位状态寄存器来 ...
- CentOS下安装Chrome浏览器
1. 下载安装脚本, 在下载目录中,执行以下命令,将安装脚本下载到本地 wget https://intoli.com/install-google-chrome.sh 2.然后授予可执行权限 chm ...
- Android逆向之旅---基于对so中的函数加密技术实现so加固
一.前言 今天我们继续来介绍so加固方式,在前面一篇文章中我们介绍了对so中指定的段(section)进行加密来实现对so加固 http://blog.csdn.net/jiangwei0910410 ...
- UX168办公本地环境维护记录
上班到公司 1.打考勤靠.或处理考勤异常 2.钉钉 3.邮件. 4.禅道系统 5.开启nginx.node.monogo服务 5.1.开启nginx服务 /etc/init.d/apache2 sto ...
- 实现word在线预览 有php的写法 也有插件似
<?php //header("Content-type:text/html;charset=utf-8"); //word转html 展示 $lj=$_GET['file' ...
- OpenCV笔记:pyrDown()函数和pryUp()函数的使用
OpenCV实现了用于创建图像金字塔的两个函数pyrDown()和pryUp(). 图像金字塔是一种经典的图像多尺寸描述方法,它将降采样和平滑滤波结合在一起,对图像进行多尺度表示.图像金字塔由不同尺寸 ...