欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2162B.Beautiful String
Beautiful String
You are given a binary string of length .
Your task is to find any subsequence of such that:
- The subsequence is non-decreasing. That is, each character in is not greater than the next one.
- Let denote the string obtained by removing all characters of from , while preserving the order of the remaining characters. Then must be a palindrome.
You only need to output any valid subsequence that satisfies both conditions. If no such subsequence exists, output .
Note that an empty string is both non-decreasing and a palindrome.
A binary string is a string consisting of characters '0' and '1'.
A subsequence of a string is a sequence such that . The characters are selected in order, but not necessarily contiguously. Note that an empty string is a subsequence of any string.
A string is a palindrome if for all . In other words, the string reads the same forward and backward.
Input
The first line contains a single integer () — the number of test cases.
The first line of each test case contains a single integer () — the length of the string.
The second line contains a binary string of length .
Output
If a solution exists:
- On the first line, print a single integer () — the length of the subsequence .
- On the second line, print distinct integers () — the indices of the characters in that form (in order as they appear in ).
Otherwise, print a single line containing .
Note
In the first test case, we remove an empty string, resulting in , which is a palindrome.
In the second test case, we remove (indices , ), resulting in , which is a palindrome.
In the third test case, we remove (indices to ), resulting in an empty string, which is trivially a palindrome.
In the fourth test case, we remove (indices , ), resulting in , which is a palindrome.
In the fifth test case, we remove (indices , ), resulting in , which is a palindrome.
Samples
5
3
010
3
001
5
00111
8
11010011
6
100101
0
2
2 3
5
1 2 3 4 5
2
3 4
2
5 6
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |