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 ...
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 i...
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 FU...
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 ...
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 co...
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 AS...
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 ...
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: p...
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 NU...
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 ...
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] an...
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 ...
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 ...
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 i...
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 V...
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 ...
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...
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 VA...
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 ...
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) els...
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 VA...
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 ...
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(...
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 ...
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 ...
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...
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 AS...
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 ...
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...
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...
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 ...
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 = []...
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 ...
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 ...
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...
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...
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 ...
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] = ...
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 F...
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 ...
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 e...
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...
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 ...
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 ...
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 V...
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 ...
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(...
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 VA...
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 ...
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(inp...
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_CAL...
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 ...
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: pr...
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...
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 ...
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_CAL...
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 ...
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 r...
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 V...
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 ...
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...
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 STR...
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 ...
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[...
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...
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 ...
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): ...
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 ...
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 ...
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.ad...
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 ...
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 ...
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 ran...
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 ...
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 ...
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 i...
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 S...
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 ...
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: ...
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...
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 ...
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[...
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...
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 ...
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:...
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 BI...
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 ...
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(a...
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...
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 ...
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...
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 V...
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 ...
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"...
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 STR...
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 ...
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...
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 FUN...
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 ...
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 ra...
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 ASSI...
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 ...
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 ...
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 ...
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 ...
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(...
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 FU...
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 ...
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]: ...
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 ...
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 ...
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")] = ...
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_CA...
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 ...
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 i...
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...
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 ...
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 + ...
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...
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 ...
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 [...
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...
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 ...
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]) ...
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...
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 ...
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) ...
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_...
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 ...
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) ...
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 AS...
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 ...
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] =...
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 NU...
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 ...
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...
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 ASSIG...
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 ...
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...
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 ...
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(firs...
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_...
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 ...
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...
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 ...
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 ...
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...
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 ...
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 = c...
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 VA...
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 ...
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...
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 V...
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 ...
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[...
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 N...
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 ...
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 ...
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...
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 V...
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 ...
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...
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 ...
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]]: ...
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 ...
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 ...
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] != ...
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 ...
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 ...
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 r...
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 NUMB...
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 ...
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 el...
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 ...
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 ...
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_...
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 ...
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 ...
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(m...
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_O...
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 ...
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 STR...
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 ...
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 ...
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 B...
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 ...
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]] ...
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 VA...
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 ...
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()...
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 ...
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 ...
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 or...
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_O...
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 ...
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: ...
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...
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 ...
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, en...
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 NUMB...
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 ...
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 li...
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 ...
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 ...
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 ...
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...
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 ...
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") ...
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...
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 ...
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_CA...
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 ...
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: prin...
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_C...
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 ...
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) ...
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_O...
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 ...
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...
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 VA...
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 ...
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 ...
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...
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 ...
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 ...
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 V...
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 ...
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_ = m...
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...
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 ...
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(d...
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_CAL...
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 ...
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) ...
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...
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 ...
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] ...
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 N...
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 ...
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]) ...
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 VA...
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 ...
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.app...
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_CA...
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 ...
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") ...
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...
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 ...
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 ...
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...
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 NU...
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 ...
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,...
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 A...
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 ...
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 F...
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 ...
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 ...
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]...
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 AS...
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 ...
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]...
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 FU...
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 ...
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 p...
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 B...
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 ...
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 ...
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 ...
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...
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...
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 ...
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] = ...
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 ...
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 ...
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])] ...
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 FUN...
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 ...
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, ...
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 ...