#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
string s;
pair<int,int>p[200007];
int ans[200007];
char b[200007];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;++i){
int m;
cin>>m>>s;
if(m==1){
cout<<1<<"\n";
continue;
}
for(int j=0;j<m;++j)
p[j]={s[j]-'0',j};
sort(p,p+m);
int pos=m;
ans[p[0].second]=1;
for(int j=1;j<m;++j){
if(p[j].second<p[j-1].second){//遇到比前一个数字大的并且出现的位置在它之前的
pos=j;//就此截断
break;
}
else
ans[p[j].second]=1;//出现的位置比前一个晚,都染成1没问题
}
int now=pos;
while(now<m&&p[now].first==p[pos].first&&p[now].second<p[pos-1].second){
++now;
ans[p[now-1].second]=2;//数字和pos截断点的数字一样大并且出现的位置也都小于截断点之前的位置,全部染成2
}
for(int j=now;j<m;++j){
if(p[j].first==p[pos].first)//此时now所在位置的元素要么比pos所在的元素要大,要么出现的位置就比pos要晚
ans[p[j].second]=1;//如果是出现的位置晚的话染成1
else
ans[p[j].second]=2;//如果是更大的话染成2
}
int cnt=0;
for(int j=0;j<m;++j)
if(ans[j]==1)
b[++cnt]=s[j];
for(int j=0;j<m;++j)
if(ans[j]==2)
b[++cnt]=s[j];
int flag=0;
for(int j=2;j<=m;++j)
if(b[j]<b[j-1])//把染好色的数组分别按照1,2放进b数组进行检查,如果不是非递减序,则输出-,否则输出染色答案
flag=1;
if(flag)
cout<<"-";
else
for(int j=0;j<m;++j)
cout<<ans[j];
cout<<"\n";
}
return 0;
}

Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)C的更多相关文章

  1. 状压DP--Rotate Columns (hard version)-- Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)

    题意:https://codeforc.es/problemset/problem/1209/E2 给你一个n(1-12)行m(1-2000)列的矩阵,每一列都可以上下循环移动(类似密码锁). 问你移 ...

  2. Cow and Snacks(吃点心--图论转换) Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)

    题意:https://codeforc.es/contest/1209/problem/D 有n个点心,有k个人,每个人都有喜欢的两个点心,现在给他们排个队,一个一个吃,每个人只要有自己喜欢的点心就会 ...

  3. Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2) G1. Into Blocks (easy version)

    题目:https://codeforc.es/contest/1209/problem/G1 题意:给你一个序列,要你进行一些操作后把他变成一个好序列,好序列的定义是,两个相同的数中间的数都要与他相同 ...

  4. Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)

    怎么老是垫底啊. 不高兴. 似乎 A 掉一道题总比别人慢一些. A. Paint the Numbers 贪心,从小到大枚举,如果没有被涂色,就新增一个颜色把自己和倍数都涂上. #include< ...

  5. codeforces(Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) )(C,D)

    C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) B. Verse Pattern 水题

    B. Verse Pattern 题目连接: http://codeforces.com/contest/722/problem/B Description You are given a text ...

  7. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)(set容器里count函数以及加强for循环)

    题目链接:http://codeforces.com/contest/722/problem/D 1 #include <bits/stdc++.h> #include <iostr ...

  8. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A B C D 水 模拟 并查集 优先队列

    A. Broken Clock time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  9. 二分 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D

    http://codeforces.com/contest/722/problem/D 题目大意:给你一个没有重复元素的Y集合,再给你一个没有重复元素X集合,X集合有如下操作 ①挑选某个元素*2 ②某 ...

随机推荐

  1. i.MX RT1010之FlexIO模拟SSI外设

    恩智浦的i.MX RT1010是跨界处理器产品,作为i.MX RT跨界MCU系列的一个新的切入点,i.MX RT1010是成本最低的LQFP封装方式与i.MX RT系列产品一贯的高性能和易用性的结合产 ...

  2. 算法进阶:0x01 位运算

    一.快速幂的模板代码 a^b%p: #include<iostream> using namespace std; int main() { int a,b,p; cin>>a ...

  3. Jmeter BeanShell笔记

    前言:beanshell是支持java语法的,因此当一些复杂的数据结构jmeter处理不了的时候,我们可以借助于java来实现 1,使用beanshell处理JDBC请求返回的值 数据库结构 当JDB ...

  4. celery task - 2

    # celery task 前言 讨论一个定时任务,一般而言,需要的功能如下: 封装成对象,独立执行: 对象有一些接口,便于了解它的状态: 定时调用: 行为控制,包括重试,成功/失败回调等: 下面分别 ...

  5. python中文本的读写操作

    文本的操作 函数的排序操作: def func(i): return i[2] list=[('曹操',101,'c'),('吕布',100,'d'),('刘备',200,'l'),('大乔',50, ...

  6. js 一句代码 让网页变为编辑器

    document.body.contentEditable = true 只要在控制台执行这行语句   页面就可以自由输入编辑了

  7. Laravel Vuejs 实战:开发知乎 (9)定义话题与问题关系

    1.话题[Topic] 执行命令: php artisan make:model Topic –cmr 修改****_**_**_create_topics_table.php数据库迁移文件如下: c ...

  8. python练习:使用二分法查找求近似平方根,使用二分法查找求近似立方根。

    python练习:使用二分法查找求近似平方根,使用二分法查找求近似立方根. 重难点:原理为一个数的平方根一定在,0到这个数之间,那么就对这之间的数,进行二分遍历.精确度的使用.通过最高值和最低值确定二 ...

  9. C语言:将3*5矩阵中第k列的元素左移到第0列,第k列以后的每列元素依次左移,原来左边的各列依次绕到右边。-在m行m列的二维数组中存放如下规律的数据,

    //将3*5矩阵中第k列的元素左移到第0列,第k列以后的每列元素依次左移,原来左边的各列依次绕到右边. #include <stdio.h> #define M 3 #define N 5 ...

  10. 批量离线安装jar 包到maven本地仓库

    //installer.bat@echo offset localdir=%~dp0call mvn install:install-file -DgroupId=org.zhixun -Dartif ...