description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
def dfs(adj, u, color):
for v in adj[u]:
if color[v] is None:
color[v] = color[u] ^ 1
if dfs(adj, v, color):
return True
elif color[v] != color[u] ^ 1:
return True
return False
n = int(input())
s = input()
adj = [[] for _ in range(n)]
for i in range(n):
for j in range(i + 1, n):
if s[i] > s[j]:
adj[i].append(j)
adj[j].append(i)
color = [None] * n
bad = False
for u in range(n):
if color[u] is None:
color[u] = 0
if dfs(adj, u, color):
bad = True
break
if bad:
print("NO")
else:
print("YES")
print(*color, sep="")
|
FUNC_DEF FOR VAR VAR VAR IF VAR VAR NONE ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR RETURN NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NONE ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
ans = [1]
cc = 0
color = ["z"] * 26
color[0] = s[0]
for i in range(1, n):
flag = False
for j in range(cc + 1):
if color[j] <= s[i]:
ans.append(j + 1)
flag = True
color[j] = s[i]
break
if not flag:
cc += 1
color[cc] = s[i]
ans.append(cc + 1)
print(cc + 1)
for i in range(n):
print(ans[i], end=" ")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST STRING NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
input()
arr = input().strip()
ans = []
color = 0
mx = [(0) for i in range(26)]
for i in arr:
c = ord(i) - 97
_max = 0
for j in range(c + 1, 26):
_max = max(_max, mx[j])
ans.append(_max + 1)
color = max(color, ans[-1])
mx[c] = max(mx[c], _max + 1)
if color > 2:
print("NO")
else:
print("YES")
for i in ans:
print(i - 1, end="")
|
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
string = input()
arr = [(ord(i) - 96) for i in string]
lmax = arr[0]
ans = "0"
flag = 0
flag2 = 1
for i in range(1, n):
if arr[i] < lmax:
if flag:
if arr[i] < fmax:
flag2 = 0
break
else:
fmax = arr[i]
ans += "1"
else:
flag = 1
fmax = arr[i]
ans += "1"
else:
lmax = arr[i]
ans += "0"
if flag2:
print("YES")
print(ans)
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR IF VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR STRING IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
a = []
for i in range(n):
a.append([s[i], i, 0])
for i in range(n):
mn = a[i][0]
k = i
for j in range(i + 1, n):
if a[j][0] < mn:
mn = a[j][0]
k = j
if k == i:
continue
if a[k][2]:
print("NO")
exit()
for j in range(k, i, -1):
a[j - 1][2] = 1
a[j - 1], a[j] = a[j], a[j - 1]
ans = [0] * n
for i in range(n):
pos, color = a[i][1], a[i][2]
ans[pos] = color
print("YES")
print("".join(map(str, ans)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
input()
string = input()
colors = [0] * 26
res = []
visited = set()
for char in string:
i1 = ord(char) - ord("a")
color = 0
for v in visited:
i2 = ord(v) - ord("a")
if char < v:
color = max(color, colors[i2])
color += 1
colors[i1] = color
res.append(color)
visited.add(char)
print(max(colors))
print(" ".join(str(i) for i in res))
|
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
prev = -1
ans = ""
t = -1
flag = 1
for i in range(n):
cur = ord(s[i]) - ord("a")
if cur >= prev:
ans += "1"
prev = cur
else:
if cur < t:
flag = 0
break
t = cur
ans += "0"
if flag:
print("YES")
print(ans)
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR VAR VAR STRING ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR STRING IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
it = list(input())
it = [(ord(i) - 97) for i in it]
lds = [1]
pre = [(0) for i in range(26)]
pre[it[0]] = 1
for i in range(1, n):
lds.append(1)
pre[it[i]] = max(pre[it[i]], 1)
for j in range(it[i] + 1, 26):
pre[it[i]] = max(pre[it[i]], pre[j] + 1)
lds[-1] = pre[it[i]]
print(max(lds))
print(*lds)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
alp = "abcdefghijklmnopqrstuvwxyz"
dic = {}
for i, s in enumerate(alp):
dic[s] = i
lis = [-1] * 27
n = int(input())
S = input()
ans = []
for i, s in enumerate(S):
ind = dic[s]
ans.append(max(lis[ind + 1 :]) + 1)
lis[ind] = ans[-1]
if max(ans) <= 1:
print("YES")
print("".join(map(str, ans)))
else:
print("NO")
|
ASSIGN VAR STRING ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
N = int(input())
s = input()
C = [0] * N
Sf = [0]
risultato = True
for n in range(1, N):
if s[n] >= s[Sf[-1]]:
Sf.append(n)
else:
C[n] = 1
u = Sf[-1]
Sf[-1] = n
Sf.append(u)
i = 3
while n >= 2 and i <= len(Sf) and s[n] < s[Sf[-i]]:
if C[n] == C[Sf[-i]]:
risultato = False
break
else:
i = i + 1
if risultato == False:
break
if risultato:
print("YES")
r = ""
for c in C:
r = r + str(c)
print(r)
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
from itertools import tee
def line():
return map(int, input().split())
def num():
return int(input())
def pairwise(it):
a, b = tee(it)
next(b, None)
return zip(a, b)
n = num()
s = input()
q = sorted((i, j) for j, (c, i) in enumerate(sorted((c, i) for i, c in enumerate(s))))
w = [q[0]]
e = []
for i, j in q[1:]:
if j > w[-1][1]:
w.append((i, j))
else:
e.append((i, j))
if all(j1 < j2 for (i1, j1), (i2, j2) in pairwise(e)):
print("YES")
kw, ke = 0, 0
ans = []
while kw < len(w) or ke < len(e):
if kw < len(w) and ke < len(e):
if w[kw][0] < e[ke][0]:
ans.append("0")
kw += 1
else:
ans.append("1")
ke += 1
elif kw < len(w):
ans.append("0")
kw += 1
else:
ans.append("1")
ke += 1
print("".join(ans))
else:
print("NO")
|
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NONE RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR NUMBER IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
b, w = [s[0]], []
ans = "YES"
for i in range(1, n):
if s[i] >= b[-1]:
b.append(s[i])
elif len(w) == 0 or s[i] >= w[-1]:
w.append(s[i])
else:
ans = "NO"
break
if ans == "YES":
print(ans)
j, k = 0, 0
for i in range(n):
if j < len(b) and s[i] == b[j]:
print("0", end="")
j += 1
else:
print("1", end="")
k += 1
print()
else:
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR LIST VAR NUMBER LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING STRING VAR NUMBER EXPR FUNC_CALL VAR STRING STRING VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = list(input())
adj_list = [[] for i in range(n)]
for i in range(n):
for j in range(i + 1, n):
if s[j] < s[i]:
adj_list[i].append(j)
adj_list[j].append(i)
color = [-1] * n
feasible = True
for i in range(n):
if color[i] == -1:
l = [i]
color[i] = 0
while len(l) > 0:
cur = l.pop()
for child in adj_list[cur]:
if color[child] == color[cur]:
feasible = False
elif color[child] == -1:
l.append(child)
color[child] = 1 - color[cur]
if feasible:
print("YES")
print("".join(map(str, color)))
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
ar = [-1] * n
b = True
for i in range(n - 1):
if ar[i] == -1:
ar[i] = 0
for j in range(i + 1, n):
if s[i] > s[j]:
if ar[j] == -1 and ar[i] == 0:
ar[j] = 1
elif ar[j] == -1 and ar[i] == 1:
ar[j] = 0
elif ar[j] != -1:
if ar[j] == ar[i]:
b = False
break
if b == False:
break
if ar[n - 1] == -1:
ar[n - 1] = 0
if b == False:
print("NO")
else:
print("YES")
for j in ar:
print(j, end="")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = list(input())
a = []
for i in range(n):
a.append([s[i], i])
a.sort()
f = ["0"] * n
w = -1
tf = False
g = [0] * n
for i in range(n):
if a[i][1] + g[a[i][1]] == i:
pass
elif g[a[i][1]] == 0:
g[a[i][1]] = 1
for j in range(a[i][1] - 1, -1, -1):
g[j] += 1
f[a[i][1]] = "1"
else:
tf = True
break
if tf:
print("NO")
else:
print("YES")
print("".join(f))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR IF VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
seq = input()
l1 = []
l2 = []
possible = True
l1.append(seq[0])
i = 0
for i in range(1, n):
if seq[i] >= seq[i - 1]:
l1.append(seq[i])
else:
l2.append(seq[i])
break
i += 1
while i < n:
if seq[i] >= l1[len(l1) - 1]:
l1.append(seq[i])
elif seq[i] >= l2[len(l2) - 1]:
l2.append(seq[i])
else:
possible = False
break
i += 1
i = 0
j = 0
if possible:
print("YES")
for char in seq:
if i < len(l1) and char == l1[i]:
print("0", end="")
i += 1
else:
print("1", end="")
j += 1
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING STRING VAR NUMBER EXPR FUNC_CALL VAR STRING STRING VAR NUMBER EXPR FUNC_CALL VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
def dfs(no, par=-1, c=0):
nonlocal adj, vis, col, st
col[no] = c
for i in adj[no]:
if vis[i] == 1:
if col[i] == col[no]:
st = 0
continue
else:
continue
vis[i] = 1
dfs(i, no, 1 - c)
n = int(input())
s = list(input())
s = [(ord(i) - 97) for i in s]
if sorted(s) == s:
print("YES")
print("0" * n)
else:
st = 1
adj = [[] for i in range(n)]
for i in range(n):
for j in range(i):
if s[i] < s[j]:
adj[i].append(j)
adj[j].append(i)
col = [(-1) for i in range(n)]
vis = [(0) for i in range(n)]
st = 1
for i in range(n):
if vis[i] == 0:
vis[i] = 1
dfs(i)
if st:
col = [str(i) for i in col]
print("YES")
print("".join(col))
else:
print("NO")
|
FUNC_DEF NUMBER NUMBER ASSIGN VAR VAR VAR FOR VAR VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
rama = []
for i in range(n):
rama.append(ord(s[i]) - 96)
visit = [(1) for i in range(27)]
a = []
maxi = 0
for i in range(n):
p = visit[rama[i]]
a.append(p)
maxi = max(maxi, p)
for j in range(rama[i]):
visit[j] = max(visit[j], p + 1)
print(maxi)
for i in a:
print(i, end=" ")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
res = ""
lst0 = "a"
lst1 = "a"
ans = "YES"
for i in range(n):
if s[i] >= lst0:
res += "0"
lst0 = s[i]
elif s[i] >= lst1:
res += "1"
lst1 = s[i]
else:
ans = "NO"
if ans == "NO":
print(ans)
else:
print("YES")
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR STRING ASSIGN VAR VAR VAR IF VAR VAR VAR VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR STRING IF VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
fl = True
dp = [1] * n
for i in range(1, n):
for j in range(i):
if s[j] > s[i]:
dp[i] = max(dp[i], 1 + dp[j])
for i in dp:
if i >= 3:
fl = False
break
if not fl:
print("NO")
else:
print("YES")
mn1 = s[0]
ans = str(0)
for i in range(1, n):
if s[i] >= mn1:
ans += "0"
mn1 = s[i]
else:
ans += "1"
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR FOR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
import sys
a = int(sys.stdin.readline())
s = sys.stdin.readline().strip()
s1 = s[0]
s2 = ""
p = ""
f = False
for i in s:
if i >= s1[-1]:
s1 += i
p += "0"
elif not s2 or i >= s2[-1]:
s2 += i
p += "1"
else:
print("NO")
f = True
break
if not f:
print("YES")
print(p)
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR VAR VAR STRING IF VAR VAR VAR NUMBER VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = str(input())
p1 = []
p2 = []
ans = []
flag = False
for elem in s:
if len(p1) == 0:
p1.append(elem)
ans.append(0)
elif ord(p1[-1]) <= ord(elem):
p1.append(elem)
ans.append(0)
elif len(p2) == 0:
p2.append(elem)
ans.append(1)
elif ord(p2[-1]) <= ord(elem):
p2.append(elem)
ans.append(1)
else:
flag = True
if flag:
print("NO")
else:
print("YES")
print("".join(map(str, ans)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = list(str(input()))
for i in range(n):
s[i] = ord(s[i]) - ord("a") + 1
dp = [[([0] * 27) for i in range(27)] for j in range(n + 1)]
dp[0][0][0] = ""
p = [[([0] * 27) for i in range(27)] for j in range(n + 1)]
for i in range(n):
c = s[i]
for j in range(27):
for k in range(27):
if dp[i][j][k] == 0:
continue
if c >= j:
dp[i + 1][c][k] = 1
p[i + 1][c][k] = [[j, k], "0"]
if c >= k:
dp[i + 1][j][c] = 1
p[i + 1][j][c] = [[j, k], "1"]
x = -1
y = -1
for j in range(27):
for k in range(27):
if dp[-1][j][k] != 0:
x = j
y = k
if x == -1 and y == -1:
print("NO")
exit()
ans = ""
for i in reversed(range(n)):
prvx = p[i + 1][x][y][0][0]
prvy = p[i + 1][x][y][0][1]
ans = p[i + 1][x][y][1] + ans
x = prvx
y = prvy
print("YES")
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR LIST LIST VAR VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR LIST LIST VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
from sys import stdin, stdout
t = 1
for _ in range(t):
n = int(input())
s = input()
ans = []
dict = {}
count = 0
for i in s:
count += 1
maxi = -1
taken = set()
for j in range(97 + 25, 96, -1):
if chr(j) in dict and chr(j) > i:
taken.add(dict[chr(j)][1])
j = 0
while 1:
j += 1
if j not in taken:
ans.append(j)
dict[i] = count, j
break
x = len(set(ans))
if x > 2:
print("no")
continue
print("yes")
for i in range(n):
ans[i] -= 1
ans[i] = str(ans[i])
print("".join(ans))
|
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [([c] * b) for i in range(a)]
def list3d(a, b, c, d):
return [[([d] * c) for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[([e] * d) for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
INF = 10**18
MOD = 10**9 + 7
def bisearch_min(mn, mx, func):
ok = mx
ng = mn
while ng + 1 < ok:
mid = (ok + ng) // 2
if func(mid):
ok = mid
else:
ng = mid
return ok
def check(m):
if m == len(B):
return True
if B[m][-1][0] <= a:
return True
else:
return False
N = INT()
A = [(ord(c) - 97) for c in input()]
B = [[] for i in range(1)]
B[0].append((A[0], 0))
for i, a in enumerate(A[1:], 1):
idx = bisearch_min(-1, len(B), check)
if idx == len(B):
B.append([(a, i)])
else:
B[idx].append((a, i))
ans = [0] * N
for a, li in enumerate(B):
for _, idx in li:
ans[idx] = str(a)
if len(B) <= 2:
YES()
print("".join(ans))
else:
NO()
|
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NONE RETURN VAR NONE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR NUMBER NUMBER VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
import sys
n = int(sys.stdin.readline())
s = list(sys.stdin.readline().strip())
s0, s1 = "", ""
color = ""
works = True
for i in s:
if s0 == "" or s0[-1] <= i:
s0 += i
color += "0"
elif s1 == "" or s1[-1] <= i:
s1 += i
color += "1"
else:
works = False
break
if works == True:
print("YES")
print(color)
else:
print("NO")
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR STRING STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR VAR VAR VAR STRING IF VAR STRING VAR NUMBER VAR VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
l = [-1] * n
flag = True
def check(f, l, i, s):
for j in range(i - 1, -1, -1):
if s[i] < s[j]:
if l[j] == -1:
l[j] = 1 - f
elif l[j] == f:
return False
return True
for i in range(n - 1, -1, -1):
if l[i] == 0:
for j in range(i - 1, -1, -1):
if s[i] < s[j]:
if l[j] == -1:
l[j] = 1
elif l[j] == 0:
flag = False
break
elif l[i] == 1:
for j in range(i - 1, -1, -1):
if s[i] < s[j]:
if l[j] == -1:
l[j] = 0
elif l[j] == 1:
flag = False
break
if flag == False:
break
else:
l[i] = 1
if check(1, l, i, s):
l[i] = 1
continue
elif check(0, l, i, s):
l[i] = 0
continue
else:
flag = False
break
if flag == False:
print("NO")
else:
print("YES")
for i in l:
print(i, end="")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
from sys import stdin, stdout
class Solve:
def __init__(self):
R = stdin.readline
W = stdout.write
n = int(input())
s = [x for x in R()]
s.pop()
tmps = [] + s
sor = sorted(s)
ans = ["0" for i in range(n)]
for i in range(n):
if s[i] != sor[i]:
flg = 0
for j in range(i + 1, n):
if s[j] == sor[i]:
for k in range(j, i, -1):
s[k] = s[k - 1]
if k == j:
if ans[k] == "1":
W("NO")
return
ans[k] = "1"
s[i] = sor[i]
break
tmpans = [] + ans
for i in range(n):
if tmps[i] != sor[i]:
for j in range(i + 1, n):
if tmps[j] == sor[i]:
for k in range(j, i - 1, -1):
if tmpans[k] != tmpans[k - 1]:
tmpans[k], tmpans[k - 1] = tmpans[k - 1], tmpans[k]
tmps[k], tmps[k - 1] = tmps[k - 1], tmps[k]
else:
W("NO")
return
break
W("YES\n")
W("".join(ans))
def main():
s = Solve()
main()
|
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR STRING ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
dp = [(0) for i in range(30)]
ans = [(1) for i in range(n)]
for i in range(n):
tmp = ord(s[i]) - ord("a")
for j in range(tmp + 1, 26):
ans[i] = max(ans[i], dp[j] + 1)
dp[tmp] = ans[i]
if max(ans) <= 2:
print("YES")
for i in ans:
print(i - 1, end="")
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
k = ["a"] * 26
ans = []
maxColor = 1
c = 0
for symb in input():
for i in range(len(k)):
if symb >= k[i]:
ans.append(str(i + 1))
if i + 1 > maxColor:
maxColor = i + 1
k[i] = symb
break
c += 1
print(maxColor)
print(" ".join(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
zero = False
one = False
mx = s[n - 1]
zero = True
final = ["0"]
o = ""
z = s[n - 1]
ans = 1
for i in range(n - 2, -1, -1):
if s[i] <= z:
z = s[i]
final.append("0")
elif s[i] > z:
if o == "":
o = s[i]
final.append("1")
elif s[i] > o:
ans = -1
break
else:
o = s[i]
final.append("1")
if ans == -1:
print("NO")
else:
print("YES")
print("".join(final[::-1]))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST STRING ASSIGN VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR IF VAR STRING ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
def string(n, s):
res = ""
j = k = "a"
for i in range(n):
if s[i] >= j:
res += "0"
j = s[i]
elif s[i] >= k:
res += "1"
k = s[i]
else:
return "NO"
return ["YES", res]
n = int(input())
s = input()
if string(n, s) == "NO":
print("NO")
else:
print(*string(n, s), sep="\n")
|
FUNC_DEF ASSIGN VAR STRING ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR STRING ASSIGN VAR VAR VAR IF VAR VAR VAR VAR STRING ASSIGN VAR VAR VAR RETURN STRING RETURN LIST STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
string = input()
l = []
a1 = "a"
b1 = "a"
t = 0
for i in range(n):
if string[i] >= a1:
l.append(0)
a1 = string[i]
elif string[i] >= b1:
l.append(1)
b1 = string[i]
else:
t = 1
break
if t == 1:
print("NO")
else:
print("YES")
for i in range(n):
print(l[i], end="")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
import sys
def input():
return sys.stdin.readline().rstrip()
def f(char):
return ord(char) - ord("a")
def slv():
n = int(input())
a = list(input())
a = list(map(f, a))
if n == 1:
print("YES")
print(0)
return
ans = [0] * n
sorted_ans = [0] * n
for i in range(n - 2, -1, -1):
v = a[i]
if v > a[i + 1]:
ans[i] = 1
sorted_ans[i] = 1
for j in range(i, n - 1):
if a[j] > a[j + 1]:
if sorted_ans[j] == sorted_ans[j + 1]:
print("NO")
return
else:
a[j], a[j + 1] = a[j + 1], a[j]
sorted_ans[j], sorted_ans[j + 1] = (
sorted_ans[j + 1],
sorted_ans[j],
)
else:
break
else:
continue
print("YES")
print("".join(map(str, ans)))
return
def main():
t = 1
for i in range(t):
slv()
return
main()
|
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR RETURN FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN EXPR FUNC_CALL VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
t = 1
while t != 0:
t -= 1
n = int(input())
s = input()
l1, l2 = "a", "a"
ans = ""
for i in range(n):
if s[i] >= l1:
l1 = s[i]
ans += "0"
elif s[i] >= l2:
l2 = s[i]
ans += "1"
else:
ans = "NO"
break
if ans == "NO":
print(ans)
else:
print("YES")
print(ans)
|
ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR STRING STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR STRING IF VAR VAR VAR ASSIGN VAR VAR VAR VAR STRING ASSIGN VAR STRING IF VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
def main():
n = int(input().strip())
s = input().strip()
result = []
a, b = "", ""
for c in s:
if c >= a:
a = c
result.append("1")
elif c >= b:
b = c
result.append("0")
else:
print("NO")
return
print("YES")
print("".join(result))
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR STRING STRING FOR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
def main():
n = int(input())
ss = list(zip(input(), range(0, n)))
prev = " "
res = ["0"] * n
for i in range(1, n):
if ss[i][0] < ss[i - 1][0]:
if res[ss[i - 1][1]] == "0":
res[ss[i][1]] = "1"
j = i - 1
while j >= 0 and ss[i][0] < ss[j][0]:
if res[ss[i][1]] == res[ss[j][1]]:
print("NO")
return
else:
j -= 1
ss[j + 1 : i + 1] = [ss[i]] + ss[j + 1 : i]
print("YES")
print("".join(res))
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR VAR VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP LIST VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
def main():
n = int(input())
s = input()
dp = []
ans = []
for i in range(n - 1, -1, -1):
letters = [0] * 26
if dp:
for j in range(26):
letters[j] = dp[-1][j]
for j in range(ord(s[i]) - ord("a")):
letters[ord(s[i]) - ord("a")] = max(
letters[ord(s[i]) - ord("a")], dp[-1][j] + 1
)
letters[ord(s[i]) - ord("a")] = max(letters[ord(s[i]) - ord("a")], 1)
else:
letters[ord(s[i]) - ord("a")] = 1
ans.append(letters[ord(s[i]) - ord("a")])
dp.append(letters)
ans.reverse()
max_val = max(dp[-1])
print(max_val)
for i in ans:
print(i, end=" ")
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER IF VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
alpha_small_dict = {chr(i): (i - 97) for i in range(97, 97 + 26)}
n = int(input())
s = input()
data = [alpha_small_dict[x] for x in s]
G = [[] for _ in range(n)]
alpha_data = [[] for _ in range(26)]
color = [(0) for _ in range(n)]
max_color = [(0) for _ in range(26)]
for i, x in enumerate(data):
now = 0
for y in range(x + 1, 26):
now = max(max_color[y], now)
now += 1
alpha_data[x].append(i)
max_color[x] = max(max_color[x], now)
color[i] = now
print(max(color))
print(*color)
|
ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
a = int(input())
s = input()
ans = [0]
flag = 0
g1 = [[s[0], 0, 0]]
def fit(g1, si, i):
r = len(g1) - 1
while r >= 0 and g1[r][0] > s[i] and g1[r][1] == 0:
r -= 1
if r < 0:
g1.insert(0, [si, 1, i])
return 1
if g1[r][0] > si and g1[r][1] == 1:
return 0
g1.insert(r + 1, [si, 1, i])
return 1
for i in range(1, len(s)):
if s[i] >= g1[-1][0]:
g1.append([s[i], 0, i])
continue
if fit(g1, s[i], i):
continue
else:
flag = 1
break
if flag == 1:
print("NO")
exit(0)
print("YES")
g1.sort(key=lambda x: x[2])
for i in range(len(g1)):
print(g1[i][1], end="")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST LIST VAR NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER LIST VAR NUMBER VAR RETURN NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER RETURN NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER LIST VAR NUMBER VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
import sys
sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def SI():
return sys.stdin.readline()[:-1]
def main():
n = II()
s = SI()
col = [0] * 27
ans = [0] * n
a = ord("a")
for i, c in enumerate(s):
code = ord(c) - a
cur = max(col[code + 1 :]) + 1
ans[i] = cur
col[code] = cur
print(max(col))
print(*ans)
main()
|
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
c = 1
k = [(0) for i in range(26)]
code = ord("a")
k[0] = 1
ans = []
for i in range(n):
letter = ord(s[i]) - code
if k[letter] != 0:
ans.append(k[letter])
else:
for j in range(letter, -1, -1):
if k[j] != 0:
ans.append(k[j])
k[letter] = k[j]
k[j] = 0
break
if j == 0:
c += 1
k[letter] = c
ans.append(c)
print(c)
print(*ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
N = int(input())
s = input()
A = []
for i in range(N):
A.append((s[i], i))
A.sort()
B = [0] * N
C = [i for i in range(N)]
for i in range(N):
_, j = A[i]
B[i] = j
adj = [[] for _ in range(N)]
for i in range(N):
x = B[i]
j = C.index(x)
while i < j:
y = C[j - 1]
adj[x].append(y)
adj[y].append(x)
C[j], C[j - 1] = C[j - 1], C[j]
j -= 1
vst = [-1] * N
succ = True
for i in range(N):
if vst[i] < 0:
vst[i] = 0
for j in adj[i]:
if vst[j] < 0:
vst[j] = 1 - vst[i]
elif vst[j] + vst[i] != 1:
succ = False
if succ:
print("YES")
print("".join(map(str, vst)))
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = [(ord(i) - ord("a") + 1) for i in input()]
clr = ["1"] * n
current = 1
x = s[0]
last = [27, 1]
for i in range(n):
if s[i] >= x:
x = s[i]
last[1] = s[i]
else:
check = [(s[i] < j) for j in last]
if False in check:
c = check.index(False)
last[c] = s[i]
else:
current += 1
c = current
last.append(s[i])
clr[i] = str(c)
print(len(set(clr)))
print(" ".join(clr))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
def solve():
n = ri()
s = input().strip()
out = [-1] * n
for i in range(n):
if out[i] == -1:
out[i] = 0
for j in range(i + 1, n):
if s[j] < s[i]:
if out[i] == out[j]:
print("NO")
return
elif out[j] == -1:
out[j] = 1 - out[i]
print("YES")
print("".join(map(str, out)))
solve()
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
import sys
def main():
n = int(input())
s = input()
arr = list(s)
arr.sort()
s2 = "".join(arr)
def swap(i, j):
temp = arr[i]
arr[i] = arr[j]
arr[j] = temp
arr = []
for i, char in enumerate(s):
arr.append([char, -1, i])
i = 0
ok = True
color = []
while i < n and ok:
c1 = arr[i][1]
if c1 == -1:
c1 = 0
c2 = 1 ^ c1
for j in range(i, n):
if s2[i] == arr[j][0]:
break
if i == j:
arr[i][1] = 0
i += 1
continue
for k in range(i, j):
if arr[k][1] == c2:
ok = False
break
arr[k][1] = c1
if arr[j][1] == c1:
ok = False
arr[j][1] = c2
for k in range(j, i, -1):
swap(k, k - 1)
i += 1
if ok:
print("YES")
color = [(-1) for _ in range(n)]
for char, c, i in arr:
color[i] = c
ans = "".join([str(x) for x in color])
print(ans)
else:
print("NO")
return
input = lambda: sys.stdin.readline().rstrip("\r\n")
def oneLineArrayPrint(arr):
print(" ".join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
print("\n".join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
print("\n".join([" ".join([str(x) for x in y]) for y in arr]))
def readIntArr():
return [int(x) for x in input().split()]
def makeArr(*args):
assert (
len(args) >= 2
), "makeArr args should be (default value, dimension 1, dimension 2,..."
if len(args) == 2:
return [args[0] for _ in range(args[1])]
else:
return [makeArr(args[0], *args[2:]) for _ in range(args[1])]
def queryInteractive(x, y):
print("? {} {}".format(x, y))
sys.stdout.flush()
return int(input())
def answerInteractive(ans):
print("! {}".format(ans))
sys.stdout.flush()
inf = float("inf")
MOD = 10**9 + 7
for _abc in range(1):
main()
|
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FUNC_CALL VAR VAR NUMBER STRING IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
N = int(input())
L = input()
S = "0"
prev = L[0]
last = -1
for i in range(1, N):
if L[i] < prev:
S += "1"
if last != -1:
if L[i] < last:
print("NO")
exit(0)
last = L[i]
else:
S += "0"
prev = L[i]
print("YES")
print(S)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR STRING IF VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR STRING ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
first = []
second = []
N = int(input())
s = input()
last_first = s[0]
first.append(0)
last_second = ""
check = -1
for i in range(1, N, 1):
if last_first <= s[i]:
last_first = s[i]
first.append(i)
elif last_second == "":
last_second = s[i]
second.append(i)
check = len(first)
len_first = len(first)
if len_first != N:
for i in range(second[0] + 1, N, 1):
if check < len_first and i == first[check]:
check += 1
continue
if last_second <= s[i]:
last_second = s[i]
second.append(i)
len_second = len(second)
if len_first + len_second != N:
print("NO")
else:
result = []
i, j = 0, 0
while i < len_first and j < len_second:
if first[i] < second[j]:
result.append(0)
i += 1
else:
result.append(1)
j += 1
while i < len_first:
result.append(0)
i += 1
while j < len_second:
result.append(1)
j += 1
print("YES")
for i in range(0, N, 1):
print(result[i], end="")
print()
|
ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = list(map(ord, input()))
b = [(0) for i in range(26)]
ans = []
for i in s:
for j in range(26):
if b[j] <= i:
b[j] = i
ans.append(j + 1)
break
print(26 - b.count(0))
print(*ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
def main():
n = int(input())
s = input()
ret = [(-1) for _ in range(n)]
flag = False
for i in range(n):
se = set()
for j in range(i - 1, -1, -1):
if s[j] > s[i]:
se.add(ret[j])
if len(se) > 1:
flag = True
break
elif len(se) == 1:
ret[i] = 1 - list(se)[0]
else:
ret[i] = 0
if flag:
print("NO")
else:
print("YES")
print("".join(list(map(str, ret))))
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
def main():
n = int(input())
ss = list(zip(input(), range(0, n)))
res = [1] * n
max_colour = 1
nextx = [0] * 26
colours_after = [([True] + [False] * 26) for _ in range(26)]
for i in range(n):
ch = ord(ss[i][0]) - ord("a")
opos = ss[i][1]
nx = nextx[ch]
col = colours_after[ch].index(False)
if col > max_colour:
max_colour = col
res[opos] = col
for c in range(ch):
colours_after[c][col] = True
for c in range(ch, 26):
nextx[c] = min(nextx[c], nx + 1)
print(max_colour)
print(" ".join(map(str, res)))
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
g = {}
for i in range(len(s)):
g[i] = []
for i in range(len(s)):
for j in range(i):
if s[j] > s[i]:
g[i].append(j)
g[j].append(i)
colored = [False] * len(s)
color = [None] * len(s)
def brush(v, c):
colored[v] = True
color[v] = c
for n in g[v]:
if colored[n]:
if color[n] == c:
return False
elif not brush(n, c ^ 1):
return False
return True
failed = False
for i in range(len(s)):
if not colored[i]:
if not brush(i, 0):
failed = True
break
if failed:
print("NO")
else:
print("YES")
print("".join(map(lambda i: "1" if color[i] == 1 else "0", range(len(s)))))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR VAR IF VAR VAR IF VAR VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER STRING STRING FUNC_CALL VAR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
import sys
input = lambda: sys.stdin.readline().strip()
n = int(input())
s = input()
color = [(0) for i in range(n)]
counter = [(0) for i in range(26)]
for i in range(n):
color[i] = max(counter[ord(s[i]) - ord("a") + 1 :], default=0) + 1
counter[ord(s[i]) - ord("a")] = max(counter[ord(s[i]) - ord("a")], color[i])
print(max(color))
print(*color)
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
last0 = last1 = "a"
ans = ""
for i in range(n):
if s[i] >= last0:
ans += "0"
last0 = s[i]
elif s[i] >= last1:
ans += "1"
last1 = s[i]
else:
print("NO")
break
if len(ans) == n:
print("YES")
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR STRING ASSIGN VAR VAR VAR IF VAR VAR VAR VAR STRING ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
from sys import stdin, stdout
input = stdin.readline
def im():
return map(int, input().split())
def ii():
return int(input())
def il():
return list(map(int, input().split()))
def ins():
return input()[:-1]
n = ii()
st = ins()
l = "a"
l2 = "a"
ans = ""
for i in st:
if i >= l:
l = i
ans += "0"
elif i >= l2:
l2 = i
ans += "1"
else:
print("NO")
break
if len(ans) == len(st):
print("YES")
print(ans)
|
ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR STRING IF VAR VAR ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
r = ""
f = "a"
se = "a"
bool = True
for i in range(n):
if s[i] >= f:
r = r + "0"
f = s[i]
elif s[i] >= se:
r = r + "1"
se = s[i]
else:
bool = False
print("NO")
break
if bool:
print("YES")
print(r)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
def solve():
for i in range(n):
mine = i
for j in range(i, n):
if s[j] < s[mine]:
mine = j
if mine != i:
color = -1
for k in range(i, mine):
if ans[ind[k]] != -1:
if color != -1 and color != ans[ind[k]]:
return False
color = ans[ind[k]]
if color == -1:
ans[ind[mine]] = 0
color = 1
elif ans[ind[mine]] == -1:
ans[ind[mine]] = 1 - color
else:
if ans[ind[mine]] != 1 - color:
return False
ans[ind[mine]] = 1 - color
for k in range(i, mine):
ans[ind[k]] = color
tmp = s[mine]
tmpind = ind[mine]
for k in range(mine, i, -1):
s[k] = s[k - 1]
ind[k] = ind[k - 1]
s[i] = tmp
ind[i] = tmpind
return True
n = int(input())
s = list(input())
ans = [-1] * n
ind = list(range(n))
if solve():
print("YES")
for i in range(n):
if ans[i] == -1:
ans[i] = 0
for i in ans:
print(i, end="")
print()
else:
print("NO")
|
FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR BIN_OP NUMBER VAR RETURN NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = str(input())
tre = [[] for i in range(n)]
clr = [(-1) for i in range(n)]
for i in range(n):
for j in range(0, i):
if s[j] > s[i]:
tre[i].append(j)
for j in range(i + 1, n):
if s[j] < s[i]:
tre[i].append(j)
t = True
for i in range(n):
if clr[i] != -1:
continue
s = [i]
clr[i] = 0
while s and t:
x = s.pop()
i = clr[x]
for j in tre[x]:
if clr[j] == -1:
clr[j] = i ^ 1
s.append(j)
elif clr[j] == i:
t = False
break
if t:
print("YES")
print("".join([str(i) for i in clr]))
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
a = list(map(lambda c: ord(c) - 97, input()))
color = [0] * 26
ans = [0] * n
last = -1
for i, c in enumerate(a):
col = 0
if last <= c:
last = c
if color[c] == 0:
col = 1
else:
col = color[c] & -color[c]
else:
col = 1
for j in range(last, c, -1):
while col & color[j]:
col <<= 1
color[c] |= col
ans[i] = len(bin(col)) - 2
print(max(ans))
print(*ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
a = [-1] * 26
h = [-1] * n
ch = 1
for i in range(len(s)):
f = s[i]
y = ord(f) - 97
st = set()
for j in range(y + 1, 26):
if a[j] != -1:
st.add(a[j])
if 2 in st:
ch = 0
break
if len(st) == 0:
h[i] = 0
a[y] = 0
elif len(st) == 1:
yt = -1
if 1 in st:
yt = 1
else:
yt = 0
h[i] = 1 - yt
if a[y] == -1 or a[y] == 1 - yt:
a[y] = 1 - yt
else:
a[y] = 2
else:
ch = 0
break
if ch == 1:
print("YES")
for i in h:
print(i, end="")
print()
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF NUMBER VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR IF VAR VAR NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
c1, c2, res = "a", "a", [""] * n
for i in range(n):
if s[i] >= c1:
res[i] = "0"
c1 = s[i]
elif s[i] >= c2:
res[i] = "1"
c2 = s[i]
else:
print("NO")
break
else:
print("YES")
print("".join(res))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR STRING STRING BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
input()
x = ["a"]
d = []
for c in input():
i = 0
while c < x[i]:
i += 1
if i == len(x):
x.append(c)
x[i] = c
d.append(i + 1)
print(max(d), *d)
|
EXPR FUNC_CALL VAR ASSIGN VAR LIST STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
def solve():
n = int(input())
s = input()
color = [1] * n
prevMaxColor = [0] * 30
for i in reversed(range(n)):
c = ord(s[i]) - ord("a")
for j in range(0, c):
color[i] = max(color[i], prevMaxColor[j] + 1)
prevMaxColor[c] = max(color[i], prevMaxColor[c])
print(max(color))
for c in color:
print(c, end=" ")
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = list(map(ord, input()))
b = [(0) for i in range(26)]
ans = []
for i in s:
for j in range(26):
if b[j] <= i:
b[j] = i
ans.append(j)
break
if 26 - b.count(0) <= 2:
print("YES")
print("".join(map(str, ans)))
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP NUMBER FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = list(input())
dg = 10**6
for i in range(n):
s[i] = ord(s[i]) * dg + i
s.sort()
def init_max(init_max_val):
for i in range(n):
seg_max[i + num_max - 1] = init_max_val[i]
for i in range(num_max - 2, -1, -1):
seg_max[i] = max(seg_max[2 * i + 1], seg_max[2 * i + 2])
def update_max(k, x):
k += num_max - 1
seg_max[k] = x
while k:
k = (k - 1) // 2
seg_max[k] = max(seg_max[k * 2 + 1], seg_max[k * 2 + 2])
def query_max(p, q):
if q <= p:
return ide_ele_max
p += num_max - 1
q += num_max - 2
res = ide_ele_max
while q - p > 1:
if p & 1 == 0:
res = max(res, seg_max[p])
if q & 1 == 1:
res = max(res, seg_max[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = max(res, seg_max[p])
else:
res = max(max(res, seg_max[p]), seg_max[q])
return res
ide_ele_max = 0
num_max = 2 ** (n - 1).bit_length()
seg_max = [ide_ele_max] * 2 * num_max
res = [0] * n
for e in s:
ind = e % dg
ad = query_max(ind, n)
res[ind] = ad + 1
update_max(ind, ad + 1)
print(max(res))
print(*res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
import sys
input = sys.stdin.readline
n = int(input())
s = list(input())[:-1]
perm = [i for i in range(n)]
res = [0] * n
decided = [0] * n
decided[0] = 1
for _ in range(n):
for i in range(n - 1):
if s[perm[i]] > s[perm[i + 1]] and (
decided[perm[i + 1]] == 0 or res[perm[i + 1]] != res[perm[i]]
):
res[perm[i + 1]] = res[perm[i]] ^ 1
decided[perm[i + 1]] = 1
perm[i], perm[i + 1] = perm[i + 1], perm[i]
for i in range(n - 1):
if s[perm[i]] > s[perm[i + 1]]:
print("NO")
exit(0)
print("YES")
print("".join(list(map(str, res))))
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
import sys
n = int(input())
s = input()
l1 = [1] * n
l1[0] = 0
prev = s[0]
for i in range(1, n):
if s[i] >= prev:
l1[i] = 0
prev = s[i]
temp = []
for i in range(n):
if l1[i] == 1:
temp.append(s[i])
if len(temp) == 0:
print("YES")
print("".join(str(x) for x in l1))
sys.exit()
prev = temp[0]
for i in range(1, len(temp)):
if temp[i] < prev:
print("NO")
sys.exit()
prev = temp[i]
print("YES")
print("".join(str(x) for x in l1))
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
import sys
input = sys.stdin.readline
def main():
N = int(input())
S = input().strip()
color = []
ans = []
for i, s in enumerate(S):
if i == 0:
color.append(ord(s) - ord("a"))
ans.append(1)
else:
for j in range(len(color)):
if ord(s) - ord("a") >= color[j]:
color[j] = ord(s) - ord("a")
ans.append(j + 1)
break
else:
ans.append(len(color) + 1)
color.append(ord(s) - ord("a"))
else:
print(len(color))
print(*ans)
main()
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
ans = [-1] * n
for i in range(n - 1, -1, -1):
c = d = 0
for j in range(i - 1, -1, -1):
if s[j] > s[i] and ans[j] == 0:
c += 1
if s[j] > s[i] and ans[j] == 1:
d += 1
if c > 0 and d > 0 or ans[i] == 1 and d > 0 or ans[i] == 0 and c > 0:
print("NO")
exit()
if ans[i] == -1:
ans[i] = 0
for j in range(i - 1, -1, -1):
if s[j] > s[i]:
ans[j] = ans[i] ^ 1
print("YES")
print(*ans, sep="")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
x = int(input())
y = input()
out = [0] * x
ch = "a"
for i in range(x):
if y[i] >= ch:
ch = y[i]
out[i] = 1
ch = "a"
for i in range(x):
if y[i] >= ch and out[i] == 0:
ch = y[i]
out[i] = 2
if 0 in out:
print("NO")
else:
print("YES")
for i in out:
print(i - 1, end="")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
import sys
n = int(sys.stdin.readline())
s = sys.stdin.readline().strip()
a2int = {chr(97 + i): i for i in range(26)}
aaaaa = {"1": 1, "0": 0}
res = "YES"
list_res = ["0"] * n
list_where = [[] for _ in range(26)]
for i, now in enumerate(s):
count = [0, 0]
for j in range(a2int[now] + 1, 26):
for v in list_where[j]:
count[aaaaa[list_res[v]]] += 1
if count[0] and count[1]:
res = "NO"
break
if count[0]:
list_res[i] = "1"
else:
list_res[i] = "0"
list_where[a2int[now]].append(i)
if res == "YES":
print("YES")
print("".join(list_res))
else:
print("NO")
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR DICT STRING STRING NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
l = [[0, -1] for i in range(26)]
for i in range(n):
l[ord(s[i]) - 97][0] += 1
j = -1
color = [(-1) for i in range(n)]
for c in range(26):
i = j + 1
while l[c][0] > 0 and i < n:
if ord(s[i]) - 97 == c:
if l[c][1] == -1:
was0 = False
was1 = False
for k in range(i):
if ord(s[k]) - 97 > ord(s[i]) - 97:
if color[k] == 0:
was0 = True
if color[k] == 1:
was1 = True
if was0 and was1:
print("NO")
exit(0)
if was0:
color[i] = 1
l[c][1] = 1
else:
color[i] = 0
l[c][1] = 0
else:
color[i] = l[c][1]
l[c][0] -= 1
j = i
i += 1
mx = ord(s[j]) - 97
for i in range(j):
if color[i] != -1:
continue
if ord(s[i]) - 97 > ord(s[j]) - 97:
color[i] = 1 - color[j]
if mx > ord(s[i]) - 97:
print("NO")
exit(0)
mx = ord(s[i]) - 97
for j in range(n):
for i in range(j):
if ord(s[i]) - 97 > ord(s[j]) - 97 and color[i] == color[j]:
print("NO")
exit(0)
print("YES")
for c in color:
print(c, end="")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER NUMBER VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
l = [s[0]]
ll = []
ss = "0"
for i in range(1, n):
if l[-1] <= s[i]:
l.append(s[i])
ss += "0"
elif len(ll) == 0 or ll[-1] <= s[i]:
ll.append(s[i])
ss += "1"
else:
ss = "NO"
break
if ss == "NO":
print(ss)
else:
print("YES")
print(ss)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR STRING IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR STRING IF VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
tmp = [s[0]] + ["" for i in range(25)]
ans = [1]
for i in range(1, len(s)):
for j in range(26):
if tmp[j] <= s[i]:
ans.append(j + 1)
tmp[j] = s[i]
break
print(max(ans))
print(*ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST VAR NUMBER STRING VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
ans = [(-1) for i in range(n)]
last = chr(ord("a") - 1)
for i in range(n):
if s[i] >= last:
ans[i] = 0
last = s[i]
last = chr(ord("a") - 1)
for i in range(n):
if ans[i] == -1 and s[i] >= last:
ans[i] = 1
last = s[i]
elif ans[i] == -1:
print("NO")
exit(0)
print("YES")
print(*ans, sep="")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
alpha_small_dict = {chr(i): (i - 97) for i in range(97, 97 + 26)}
n = int(input())
s = input()
data = [alpha_small_dict[x] for x in s]
G = [[] for _ in range(n)]
alpha_data = [[] for _ in range(26)]
for i, x in enumerate(data):
for y in range(x + 1, 26):
for j in alpha_data[y]:
G[i].append(j)
G[j].append(i)
alpha_data[x].append(i)
color = [(-1) for _ in range(n)]
t = True
for i in range(n):
if color[i] == -1:
que = [[-1, i]]
color[i] = 0
while que:
pre, now = que.pop()
for to in G[now]:
if to == pre:
continue
if color[to] == color[now]:
print("NO")
exit()
elif color[to] == -1:
color[to] = 1 - color[now]
que.append([now, to])
print("YES")
for x in color:
print(x, end="")
print()
|
ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR LIST LIST NUMBER VAR ASSIGN VAR VAR NUMBER WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR FOR VAR VAR VAR IF VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
ans = [0] * n
f = 0
for i in range(n):
for j in range(i + 1, n):
if s[j] < s[i]:
if ans[j] == 1 and ans[i] == 0:
continue
if ans[j] == 1 and ans[i] == 1:
f = -1
break
ans[j] = 1 - ans[i]
if f == -1:
break
if f == -1:
print("NO")
else:
print("YES")
for i in ans:
print(i, end="")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
import sys
n = int(sys.stdin.readline().rstrip())
s = list(sys.stdin.readline().rstrip())
a1 = "a"
a2 = "a"
sol = ""
for i in s:
if i >= a1:
a1 = i
sol += "0"
elif i >= a2:
a2 = i
sol += "1"
else:
print("NO")
break
else:
print("YES")
print(sol)
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR STRING IF VAR VAR ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
prev = -1
t = -1
ans = ""
for c in s:
cur = ord(c) - ord("a")
if cur >= prev:
ans += "1"
prev = cur
else:
if cur < t:
print("NO")
exit()
ans += "0"
t = cur
print("YES")
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF VAR VAR VAR STRING ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
def check(i, n, x, y, s, dp):
if i == n:
return 1
if dp[i][x][y] != -1:
return dp[i][x][y]
ch = ord(s[i]) - 97
dp[i][x][y] = 0
if ch >= x and check(i + 1, n, ch, y, s, dp) > 0:
dp[i][x][y] = 1
elif ch >= y and check(i + 1, n, x, ch, s, dp) > 0:
dp[i][x][y] = 2
return dp[i][x][y]
n = int(input())
s = input()
dp = [[([-1] * 26) for j in range(26)] for i in range(n)]
if check(0, n, 0, 0, s, dp) == 0:
print("NO")
else:
print("YES")
ans = ""
x = 0
y = 0
for i in range(n):
ch = ord(s[i]) - 97
ans += str(dp[i][x][y] - 1)
if dp[i][x][y] == 1:
x = ch
else:
y = ch
print(ans)
|
FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR NUMBER VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
d = [([0] * 26) for _ in range(26)]
n = int(input())
s = input()
ans = [-1] * n
max_ = 0
for i, x in enumerate(s):
pos = ord(x) - 97
val = None
if pos == 25:
val = 0
else:
for _, x in enumerate(d[pos + 1]):
if x == 0:
val = _
break
max_ = max(max_, val)
ans[i] = str(val)
for j in range(pos, -1, -1):
d[j][val] = 1
if max_ > 1:
print("NO")
else:
print("YES")
print("".join(ans))
|
ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NONE IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
def char_to_int(c):
res = ord(c) - ord("a")
return res
def int_to_char(n):
n_ord = ord("a") + n
res = chr(n_ord)
return res
n = int(input())
s = input()
maxdp = [0] * 26
dp = [1] * n
for i in range(n):
si = s[i]
isi = char_to_int(si)
for c in range(25, isi, -1):
dp[i] = max(dp[i], maxdp[c] + 1)
maxdp[isi] = max(maxdp[isi], dp[i])
m = max(maxdp)
print(m)
print(" ".join(map(str, dp)))
|
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR STRING VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
ans = [-1] * n
f = True
for i in range(n):
if ans[i] == -1:
ans[i] = 0
for j in range(i + 1, n):
if s[j] < s[i]:
if ans[j] == -1:
ans[j] = (ans[i] - 1) ** 2
else:
now = ans[j]
new = (ans[i] - 1) ** 2
if new != now:
f = False
else:
ans[j] = new
if not f:
print("NO")
else:
print("YES")
for i in range(n):
print(ans[i], end="")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
def f(s, n):
s = list(s)
temp = list(zip(s, range(n)))
ans = [-1] * n
for i in range(0, n):
for j in range(n - i - 1):
if temp[j][0] > temp[j + 1][0]:
if ans[temp[j][1]] == ans[temp[j + 1][1]] == -1:
temp[j], temp[j + 1] = temp[j + 1], temp[j]
ans[temp[j][1]] = 1
ans[temp[j + 1][1]] = 0
elif ans[temp[j][1]] != -1 and ans[temp[j + 1][1]] == -1:
ans[temp[j + 1][1]] = ans[temp[j][1]] ^ 1
temp[j], temp[j + 1] = temp[j + 1], temp[j]
elif ans[temp[j + 1][1]] != -1 and ans[temp[j][1]] == -1:
ans[temp[j][1]] = ans[temp[j + 1][1]] ^ 1
temp[j], temp[j + 1] = temp[j + 1], temp[j]
elif ans[temp[j + 1][1]] ^ ans[temp[j][1]] == 1:
temp[j], temp[j + 1] = temp[j + 1], temp[j]
l = ""
for i in range(len(temp)):
l += temp[i][0]
if ans[temp[i][1]] == -1:
ans[temp[i][1]] = 0
if list(l) != sorted(l):
return "NO"
print("YES")
print(*ans, sep="")
return ""
n = int(input())
s = input()
print(f(s, n))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
n = int(input())
a = input()
ck = []
ans = [0] * n
for i, v in enumerate(a):
for j in range(len(ck)):
if ck[j][-1] <= v:
ck[j].append(v)
ans[i] = j + 1
break
if not ans[i]:
ck.append([v])
ans[i] = len(ck)
print(len(ck))
print(*ans)
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR LIST VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
def ispossible(a, col, ind):
for j in range(ind - 1, -1, -1):
if a[j][0] <= a[ind][0]:
return 1
if a[j][2] == col:
return 0
return 1
n = int(input())
S = input()
s = []
col = [(-1) for i in range(n)]
c = 0
for i in S:
if ord("a") <= ord(i) <= ord("z"):
s.append([ord(i) - ord("a"), c, -1])
c += 1
possible = 1
for i in range(26):
for j in range(n):
if s[j][0] == i:
if ispossible(s, 0, j) and s[j][2] != 1:
ind = j
s[j][2] = 0
for k in range(ind, -1, -1):
if k == 0 or s[k - 1][0] <= s[k][0]:
break
s[k - 1][2] = 1
s[k], s[k - 1] = s[k - 1], s[k]
elif ispossible(s, 1, j) and s[j][2] != 0:
s[j][2] = 1
ind = j
for k in range(ind, -1, -1):
if k == 0 or s[k - 1][0] <= s[k][0]:
break
s[k - 1][2] = 0
s[k], s[k - 1] = s[k - 1], s[k]
else:
possible = 0
break
if possible:
print("YES")
ans = [(0) for i in range(n)]
for i in s:
ans[i[1]] = i[2]
for i in ans:
print(i, end="")
else:
print("NO")
|
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR STRING FUNC_CALL VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR LIST BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
last_1 = "a"
last_2 = "a"
res = True
r = []
for c in s:
if c < last_1:
if c < last_2:
res = False
else:
r.append("1")
last_2 = max(last_2, c)
else:
last_1 = max(c, last_1)
r.append("0")
if res:
print("YES")
print("".join(r))
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n, ar, x, y, d = int(input()), input(), "a", "a", ""
for i in ar:
if i >= x:
d += "0"
x = i
elif i >= y:
d += "1"
y = i
else:
print("NO")
exit()
print("YES" + "\n" + d)
|
ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING STRING STRING FOR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING STRING VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
def find(x):
r = x
while r != f[r]:
r = f[r]
while x != r:
pre = f[x]
f[x] = r
x = pre
return r
a = input()
n = int(a)
a = input()
str = list(a)
id = [0] * n
f = [0] * 2 * n
name = [0] * 2 * n
for i in range(n):
id[i] = i
for i in range(2 * n):
f[i] = i
name[i] = -1
Find = 0
for i in range(n):
if Find:
break
for j in range(n - i - 1):
if str[j] > str[j + 1]:
str[j], str[j + 1] = str[j + 1], str[j]
id[j], id[j + 1] = id[j + 1], id[j]
fx = find(id[j])
fnx = find(id[j] + n)
fy = find(id[j + 1])
fny = find(id[j + 1] + n)
if fx == fy or fnx == fny:
Find = 1
break
else:
f[fx] = fny
f[fy] = fnx
if Find:
print("NO")
else:
print("YES")
for i in range(n):
fx = find(i)
if name[fx] < 0:
name[fx] = 0
if fx >= n:
name[find(fx - n)] = 1
else:
name[find(fx + n)] = 1
print("{:d}".format(name[fx]), end="")
|
FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
def r(t=int):
return list(map(t, input().split()))
def ri(t=int):
return t(input())
def cd(it):
ret_val = dict()
for v in it:
ret_val[v] = ret_val.get(v, 0) + 1
return ret_val
n = ri()
a = input()
ans = [0] * n
alphabet = "abcdefghijklmnopqrstuvwxyzZ"
last = [alphabet, alphabet]
for i, ai in enumerate(a):
try:
a1 = last[0].index(ai)
except ValueError:
a1 = 100
try:
a2 = last[1].index(ai)
except ValueError:
a2 = 100
m = min(a1, a2)
if m != 100:
if a1 < a2:
last[0] = last[0][a1:]
ans[i] = 0
else:
last[1] = last[1][a2:]
ans[i] = 1
else:
print("NO")
break
else:
print("YES")
print("".join(str(i) for i in ans))
|
FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR STRING ASSIGN VAR LIST VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
colors = ["_"] * 26
ans = [""] * n
idx = 0
for c in s:
for i in range(26):
if c >= colors[i]:
ans[idx] = str(i + 1)
colors[i] = c
break
idx += 1
print(26 - colors.count("_"))
print(" ".join(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING NUMBER ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
d = ""
flag = False
x = y = "a"
for i in s:
if i >= x:
d += "0"
x = i
elif i >= y:
d += "1"
y = i
else:
print("NO")
flag = True
break
if not flag:
print("YES")
print(d)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR STRING FOR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
poss = 1
l1 = []
l2 = []
arr = [(0) for i in range(n)]
for i in range(n):
if l1 == []:
l1.append(s[i])
arr[i] = 0
elif ord(s[i]) >= ord(l1[-1]):
l1.append(s[i])
arr[i] = 0
elif l2 == []:
l2.append(s[i])
arr[i] = 1
elif ord(s[i]) >= ord(l2[-1]):
l2.append(s[i])
arr[i] = 1
else:
poss = 0
break
if poss == 0:
print("NO")
else:
print("YES")
for i in arr:
print(i, end="")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR LIST EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR LIST EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
import sys
input = sys.stdin.readline
l = [0] * 26
n = int(input())
pres = [0] * 30
s = input()
s = s[: len(s) - 1]
res = [1] * n
ii = -1
mxx = -1
for i in s:
ii += 1
ind = ord(i) - ord("a")
lol = 0
mx = 1
for j in range(ind + 1, 26):
if pres[j] != 0:
lol = 1
if l[j] != 0:
if mx < l[j]:
mx = l[j]
pres[ind] = 1
if lol == 1:
l[ind] = mx + 1
res[ii] = mx + 1
if res[ii] > mxx:
mxx = res[ii]
print(mxx)
print(*res)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n, s = int(input()), input()
k = {(0): "a", (1): "a"}
ans = ""
maxColor = 1
for symb in s:
for i in range(len(k)):
if symb >= k[i]:
ans += str(i + 1) + " "
if i + 1 > maxColor:
maxColor = i + 1
k[i + 1] = "a"
k[i] = symb
break
print(maxColor)
print(ans)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER STRING STRING ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
col = [1] * n
prev = [0] * 26
for i in range(n):
code = ord(s[i]) - ord("a")
if code != 25:
col[i] = max(prev[code + 1 :]) + 1
prev[code] = col[i]
print(max(col))
print(*col)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
s = input()
x = "0"
flag = "YES"
c = 0
initial = s[0]
for i in range(1, n):
if s[i] < initial:
x += "1"
if c != 0:
if s[i] < c:
flag = "NO"
break
c = s[i]
else:
x += "0"
initial = s[i]
print(flag)
if flag != "NO":
print(x)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR STRING IF VAR NUMBER IF VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR VAR VAR STRING ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
a = input()
ref = {chr(i + 97): [] for i in range(26)}
vis = [0] * n
high = a[0]
for i in range(1, n):
if a[i] >= high:
high = a[i]
continue
ref[a[i]].append(i)
flag = 0
mi = -1
for i in ref.keys():
for j in ref[i]:
if mi < j:
mi = j
vis[j] = 1
continue
flag = 1
if flag == 1:
print("NO")
else:
print("YES")
for i in vis:
print(i, end="")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
t = 1
while t != 0:
t -= 1
n = int(input())
s = input()
aux = "abcdefghijklmnopqrstuvwxyz"
maxi = [(0) for _ in range(26)]
dp = [(1) for _ in range(n)]
for i in range(n):
for j in range(aux.find(s[i]) + 1, 26):
dp[i] = max(dp[i], maxi[j] + 1)
maxi[aux.find(s[i])] = dp[i]
st = set(dp)
print(len(st))
print(*dp)
|
ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.
You are given a string $s$ consisting of $n$ lowercase Latin letters.
You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).
After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.
The goal is to make the string sorted, i.e. all characters should be in alphabetical order.
Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.
-----Input-----
The first line of the input contains one integer $n$ ($1 \le n \le 200$) β the length of $s$.
The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.
-----Output-----
If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.
Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).
-----Examples-----
Input
9
abacbecfd
Output
YES
001010101
Input
8
aaabbcbb
Output
YES
01011011
Input
7
abcdedc
Output
NO
Input
5
abcde
Output
YES
00000
|
n = int(input())
a = list(map(lambda c: ord(c) - 97, input()))
color = [0] * 26
ans = [0] * n
last = -1
for i, c in enumerate(a):
col = 0
if last <= c:
last = c
if color[c] == 0 or color[c] == 3:
col = 1
else:
col = color[c]
else:
for j in range(last, c, -1):
if color[j] == 0:
continue
if color[j] == 3:
print("NO")
return
if col == 0:
col = color[j] ^ 3
elif col & color[j]:
print("NO")
return
color[c] |= col
ans[i] = col - 1
print("YES")
print(*ans, sep="")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR STRING
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.