CF1569A.Balanced Substring

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a string ss, consisting of nn letters, each letter is either 'a' or 'b'. The letters in the string are numbered from 11 to nn.

s[l;r]s[l; r] is a continuous substring of letters from index ll to rr of the string inclusive.

A string is called balanced if the number of letters 'a' in it is equal to the number of letters 'b'. For example, strings "baba" and "aabbab" are balanced and strings "aaab" and "b" are not.

Find any non-empty balanced substring s[l;r]s[l; r] of string ss. Print its ll and rr (1≤l≤r≤n1 \le l \le r \le n). If there is no such substring, then print −1-1 −1-1.

给你一个由 nn 个字母组成的字符串 ss,每个字母均为 'a' 或 'b'。字符串中的字母编号从 11 到 nn。

s[l;r]s[l; r] 表示字符串中从索引 ll 到 rr(含端点)的连续子串。

若一个字符串中字母 'a' 的数量等于字母 'b' 的数量,则称该字符串为平衡的。例如,字符串 "baba" 和 "aabbab" 是平衡的,而字符串 "aaab" 和 "b" 不是平衡的。

请在字符串 ss 中找出任意一个非空平衡子串 s[l;r]s[l; r],并输出其对应的 ll 和 rr(满足 1≤l≤r≤n1 \le l \le r \le n)。若不存在这样的子串,则输出 −1-1 −1-1。

输入格式

The first line contains a single integer tt (1≤t≤10001 \le t \le 1000) — the number of testcases.

Then the descriptions of tt testcases follow.

The first line of the testcase contains a single integer nn (1≤n≤501 \le n \le 50) — the length of the string.

The second line of the testcase contains a string ss, consisting of nn letters, each letter is either 'a' or 'b'.

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000)—— 测试用例的数量。

接下来是 tt 个测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤501 \le n \le 50)—— 字符串的长度。

每个测试用例的第二行包含一个字符串 ss,由 nn 个字母组成,每个字母为 'a' 或 'b'。

输出格式

For each testcase print two integers. If there exists a non-empty balanced substring s[l;r]s[l; r], then print ll rr (1≤l≤r≤n1 \le l \le r \le n). Otherwise, print −1-1 −1-1.

对于每个测试用例,输出两个整数。如果存在一个非空的平衡子串 s[l;r]s[l; r],则输出 ll rr(其中 1≤l≤r≤n1 \le l \le r \le n);否则输出 −1-1 −1-1。

输入输出样例

  • 输入#1

    4
    1
    a
    6
    abbaba
    6
    abbaba
    9
    babbabbaa

    输出#1

    -1 -1
    1 6
    3 6
    2 5

说明/提示

In the first testcase there are no non-empty balanced subtrings.

In the second and third testcases there are multiple balanced substrings, including the entire string "abbaba" and substring "baba".

在第一个测试用例中,不存在非空的平衡子串。

在第二个和第三个测试用例中,存在多个平衡子串,包括整个字符串 “abbaba” 以及子串 “baba”。

输入解题思路,AI测评打分。不知道怎么写?

首页