DCP-461: String query Back to All Problems

Medium Beginners Problems > Ad-hoc


Given an string **s** and **q** query. each query consist a single integer **k**. you have to find how many pair of index **(i,j)** are there such **j>=i and i+j=k and s[i]=s[j].** string start at index 0, end at index n-1, where n is the length of string. string consist only lower case english letter. length of string will be less than equal **1000**, there will be at most **2*10<sup>3</sup>+5** queries per test case and maximum **1000** test cases. Input: ------ Number of test case in first line, then each test case start with n (length of string) in a line , then the string in next line, 3rd line is a integer **q** (number of query) and next **q** line consist k<sub>i</sub>. **0<= k<sub>i</sub><=2n** Output: ------- For each query , print a single integer in a line, which is the answer of that query Sample Input ------------ 1 6 eiging 13 0 1 2 3 4 5 6 7 8 9 10 11 12 Sample Output ------------- 1 0 1 0 2 0 1 1 1 0 1 0 0


Problem Setter:

Md. Tariqul Islam

Please login to submit solution to this problem.

Problem Limits

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

Problem Stats

5/9

Solve/Submission

Ranking

# User Language Timing
01 feodorv C 0.48s
02 Robbinb1993 Cpp 0.89s
03 leenaiitju C 1.98s
04 tariqiitju Cpp 2.15s
Feedback

Your feedback is our precious!



Or call +88 02 9853138 for support