-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1209C.cpp
More file actions
40 lines (35 loc) · 972 Bytes
/
1209C.cpp
File metadata and controls
40 lines (35 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <bits/stdc++.h>
using namespace std;
int main() {
int t; cin >> t;
while(t--) {
int n; cin >> n;
string s; cin >> s;
int i = 1;
for(; i < s.size() && s[i] >= s[i - 1]; i++);
if(i == s.size()) {
cout << string(n, '1') << endl;
continue;
}
auto it = upper_bound(s.begin(), s.begin() + i, s[i]);
char mid = *it;
int e1 = s[i - 1], e2 = s[i];
bool ok = true;
string result(n, '1');
for(int j = it - s.begin(); j < i; j++) result[j] = '2';
for(i = i + 1; i < s.size() && ok; i++) {
if(s[i] >= mid && s[i] >= e1) {
e1 = s[i];
result[i] = '2';
}
else if(s[i] <= mid && s[i] >= e2) {
e2 = s[i];
}
else {
ok = false;
}
}
cout << (ok ? result : "-") << endl;
}
return 0;
}