Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)C
#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的更多相关文章
- 状压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)列的矩阵,每一列都可以上下循环移动(类似密码锁). 问你移 ...
- 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个人,每个人都有喜欢的两个点心,现在给他们排个队,一个一个吃,每个人只要有自己喜欢的点心就会 ...
- 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 题意:给你一个序列,要你进行一些操作后把他变成一个好序列,好序列的定义是,两个相同的数中间的数都要与他相同 ...
- Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)
怎么老是垫底啊. 不高兴. 似乎 A 掉一道题总比别人慢一些. A. Paint the Numbers 贪心,从小到大枚举,如果没有被涂色,就新增一个颜色把自己和倍数都涂上. #include< ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 二分 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D
http://codeforces.com/contest/722/problem/D 题目大意:给你一个没有重复元素的Y集合,再给你一个没有重复元素X集合,X集合有如下操作 ①挑选某个元素*2 ②某 ...
随机推荐
- SpringBoot踩坑记(HTTP 400 错误)
HTTP 400 错误 复现错误 ajax请求后台数据时有时会报 HTTP 400 错误 - 请求无效 (Bad request);出现这个请求无效报错说明请求没有进入到后台服务里:原因:1)前端提交 ...
- 红帽RHCE培训-课程1笔记内容
ssh -X root@s0 1.环境变量 env 系统变量名都为大写; 引用变量名对应的值时使用$引导: SHELL下,修改变量临时生效. # PS1=' # ' # echo $PS1 永久生效放 ...
- AT24C02芯片学习记录
1.首先看AT24C02芯片的引脚说明 2.芯片的型号与存储容量(bit)的对应关系: 3.总线时序 我对时序的理解: 时钟线分两种:一种是外部时钟源控制时钟线低电平持续多久高电平持续多久,就像串口: ...
- JAVA基础学习(5)之数组
5数组 5.1数组 5.1.1初识数组 // 输出大于平均数的所有数 Scanner in = new Scanner(System.in); int n; int[] a = new int[100 ...
- 201771010135 杨蓉庆《面对对象程序设计(java)》第十七周学习总结
1.实验目的与要求 (1) 掌握线程同步的概念及实现技术: (2) 线程综合编程练习 一.理论知识 ⚫ 线程同步 (1)多线程并发运行不确定性问题解决方案:引入线 程同步机制,使得另一线程要使用该方法 ...
- 关于package.json和package-lock.json的区别
package.json文件记录你项目中所需要的所有模块.当你执行npm install的时候,node会先从package.json文件中读取所有dependencies信息,然后根据depende ...
- netty(六) buffer 源码分析
问题 : netty的 ByteBuff 和传统的ByteBuff的区别是什么? HeapByteBuf 和 DirectByteBuf 的区别 ? HeapByteBuf : 使用堆内存,缺点 ,s ...
- 【PAT甲级】1073 Scientific Notation (20 分)
题意: 输入科学计数法输出它表示的数字. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> u ...
- min-25筛总结
怕忘了赶快更一下.就是求积性函数前缀和的. 没有 \(\LaTeX\) 原理 现在你有一个积性函数 f(1)=1 FP(p) FPK(p,k) 首先要求的是前缀和,那就是f(质数)+f(合数)+f(1 ...
- Dapr Pub/Sub 集成 RabbitMQ 、Golang、Java、DotNet Core
前置条件: <Dapr运用> <Dapr 运用之 Java gRPC 调用篇> <Dapr 运用之集成 Asp.Net Core Grpc 调用篇> 搭建 Rabb ...