DCP-414: Counting in Binary String Back to All Problems

Medium Math > Counting


You are given a binary string **S** consisting of characters '0' and '1'. Your task is to count total numbers of non-overlapping and unordered pairs of substrings "01" and "10" from given binary string. That means there could be pair of either ("01","10") or ("10","01") but they should not share common indices. Input: ------ Input starts with an integer **T (1<=T<=20)**, denoting the number of test cases.<br> Each case contains an integer **N (1 ≤ N ≤ 100000)** denoting the length of binary string **S**. Next line contain a binary string. Output: ------- For each case of input, output the total number of non-overlapping and unordered pairs of substrings "01" and "10" from given binary string.<br> **See the explanation section below for more details**. Sample Input ------------ 3 4 1001 4 0110 8 10101010 Sample Output ------------- 1 1 6 **Explanation**<br> If the pair (ab,cd): "ab" indicates respectively indices of first substring and "cd" represents indices of second substring.Then, all valid pairs are:<br> In case 1: (01,23)<br> In case 2: (01,23)<br> In case 3: (01,34),(12,45),(23,56),(34,67),(01,56),(12,67)<br>


Problem Setter:

Bishal Gautam

Please login to submit solution to this problem.

Problem Limits

Language Time Limit (seconds)
C 1.00
C++ 1.00
C++14 1.00
C# 2.00
Go 2.00
Java 2.00
JavaScript 2.00
Objective-C 2.00
Perl 2.00
PHP 2.00
Python 2.00
Python3 2.00
Ruby 2.00
VB.Net 2.00

Problem Stats

74/160

Solve/Submission

Ranking

# User Language Timing
01 feodorv C 0.02s
02 sayedgkm Cpp 0.04s
03 by_default Cpp 0.04s
04 mahbubcseju Cpp 0.05s
05 tariqiitju Cpp14 0.05s
06 FariD Cpp 0.05s
07 rummanrakib11 Cpp14 0.05s
08 Hasinur_ Cpp 0.05s
09 duronto20 Cpp 0.05s
10 Durbin Cpp14 0.06s
11 sahedsohel Cpp 0.06s
12 JACKAL1586 Cpp14 0.07s
13 showmic Cpp 0.07s
14 anik_JU Cpp 0.07s
15 mbstu_alamin16 Cpp 0.07s
16 I_See_You Cpp14 0.08s
17 emrul Cpp 0.08s
18 fsshakkhor Cpp14 0.08s
19 ss1230 Cpp14 0.08s
20 khatribiru Cpp 0.09s
21 imranziad Cpp 0.09s
22 PKP_007 Cpp 0.10s
23 jamil993 Cpp 0.10s
24 mir_sabbir Cpp 0.10s
25 farhanhasin Cpp 0.11s
26 burhan103335 Cpp 0.11s
27 nasib_mbstu Cpp 0.12s
28 Taran Cpp14 0.12s
29 Superstorm Cpp14 0.13s
30 _GhOstMan_ Cpp 0.13s
31 Nobel_ruettt Cpp 0.13s
32 kzvd4729 Cpp 0.13s
33 moshiur_cse15 Cpp14 0.13s
34 AlaminJust Cpp 0.13s
35 Masum_ice Cpp 0.13s
36 inception_h Cpp 0.13s
37 dipta007 Cpp 0.13s
38 Double_O Cpp 0.13s
39 Silent_Warrior Cpp 0.13s
40 ehsan_sshuvo Cpp 0.13s
41 jalal Cpp 0.13s
42 robin_aust Cpp 0.13s
43 aumitse Cpp14 0.14s
44 _c_k_r_ Cpp 0.15s
45 shuvo_mbstu Cpp 0.15s
46 The_mover Cpp 0.15s
47 shamiul93 Cpp14 0.15s
48 Fazla Cpp 0.16s
49 arshoma_shohag Cpp 0.19s
50 astinaam Cpp14 0.22s
Feedback

Your feedback is our precious!



Or call +88 02 9853138 for support