<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      有毒的粽子

      CF1209C Paint the Digits

      You are given a sequence of n digits d1d2dn. You need to paint all the digits in two colors so that:

      • each digit is painted either in the color 1 or in the color 2;
      • if you write in a row from left to right all the digits painted in the color 1, and then after them all the digits painted in the color 2, then the resulting sequence of n digits will be non-decreasing (that is, each next digit will be greater than or equal to the previous digit).

      For example, for the sequence d=914 the only valid coloring is 211 (paint in the color 1 two last digits, paint in the color 2 the first digit). But 122 is not a valid coloring (9 concatenated with 14 is not a non-decreasing sequence).

      It is allowed that either of the two colors is not used at all. Digits painted in the same color are not required to have consecutive positions.

      Find any of the valid ways to paint the given sequence of digits or determine that it is impossible to do.

      Input

      The first line contains a single integer tt (1t10000) — the number of test cases in the input.

      The first line of each test case contains an integer nn (1≤n≤2?10^5) — the length of a given sequence of digits.

      The next line contains a sequence of n digits d1d2…dn (0≤di≤9). The digits are written in a row without spaces or any other separators. The sequence can start with 0.

      It is guaranteed that the sum of the values ??of nn for all test cases in the input does not exceed 2?10^5

      Output

      Print t lines — the answers to each of the test cases in the input.

      If there is a solution for a test case, the corresponding output line should contain any of the valid colorings written as a string of nn digits t1t2…tn (1≤ti≤2), where ti is the color the i-th digit is painted in. If there are several feasible solutions, print any of them.

      If there is no solution, then the corresponding output line should contain a single character '-' (the minus sign).

      Example
      input
      5
      12
      040425524644
      1
      0
      9
      123456789
      2
      98
      3
      987
      
      output
      121212211211
      1
      222222222
      21
      -
      
      Note

      In the first test case, d=040425524644. The output t=121212211211 is correct because 0022444 (painted in 1) concatenated with 44556 (painted in 2) is 002244444556 which is a sorted sequence of n given digits.

      題意解釋:給定T組數據,每組數據第一行輸入數字串長度,第二行輸入數字串,用數字1和2對數字串進行涂色,被1涂色的數字子串和被2涂色的數字子串拼接成新的數字串,要求新的數字串是非遞減的。

      解題思路:對原數字串進行排序,然后從后往前和從前往后各涂一次,若涂不完則輸出“-”。

      #include <bits/stdc++.h>
      using namespace std;
      int b[200005];
      int main()
      {
          int t;
          cin>>t;
          for(int i=1;i<=t;++i)
          {
              memset(b,0,sizeof(b));
              int n;
              cin>>n;
              string a;
              cin>>a;
              string c=a;
              sort(c.begin(),c.end());
              int j=n-1;
              for(int i=n-1;i>=0;--i)
              {
                  if(a[i]==c[j])
                  {
                      b[i]=2;
                      j--;
                  }
              }
              j++;
              int p=0;
              for(int i=0;i<=n-1;++i)
              {
                  if(b[i]==0&&a[i]==c[p])
                  {
                      b[i]=1;
                      p++;
                  }
              }
              if(p!=j)
              {
                  cout<<"-\n";
                  continue;
              }
              for(int i=0;i<n;++i)
              {
                  cout<<b[i];
              }
              cout<<endl;
          }
          return 0;
      }
      View Code

       

      posted on 2019-09-15 21:41  有毒的粽子  閱讀(379)  評論(0)    收藏  舉報

      主站蜘蛛池模板: 国产精品午夜福利合集| 黄页网站在线观看免费视频| 国产在线精品一区二区夜色| 欧美老少配性行为| 国产在线无码精品无码| 永久免费AV无码网站YY| 狠狠色噜噜狠狠狠狠2021| 中国女人和老外的毛片| 国产精品国产自产拍在线| 陈巴尔虎旗| 精品国产高清中文字幕| 日韩有码中文字幕国产| 午夜DY888国产精品影院| 国产精品麻豆成人av网| 亚洲一区精品伊人久久| 午夜福利影院不卡影院| 久久精品国产久精国产一老狼| 亚洲成av人片色午夜乱码| 在线视频中文字幕二区| 亚洲国产精品一区第二页| 亚洲日韩精品无码一区二区三区| 国产69精品久久久久99尤物| 亚洲av伊人久久综合性色| 青青草原国产精品啪啪视频| 蜜桃AV抽搐高潮一区二区| 女人被狂c躁到高潮视频| 亚洲精品一区二区三区色| 在线看无码的免费网站| 邻居少妇张开腿让我爽了一夜| 国产av一区二区三区综合| 成av人电影在线观看| 爱性久久久久久久久| 榆社县| 免费 黄 色 人成 视频 在 线| 久久婷婷综合色丁香五月| 人妻丰满熟妇AV无码区乱| 国产一区二区不卡视频在线| 国产福利萌白酱在线观看视频| 日韩精品久久不卡中文字幕| 国内精品久久久久影院网站| 国产综合有码无码中文字幕 |