Сагура Николай, 392, сев. филиал BoxDrawing 8993
Лукьянов Артём Васильевич, 317, Севастопольский филилал BoxDrawing 9347
t1import syst1import sys
2import unicodedata as u2import unicodedata as u
33
4def box(name: str) -> str:4def box(name: str) -> str:
5    return u.lookup('BOX DRAWINGS ' + name)5    return u.lookup('BOX DRAWINGS ' + name)
6HORIZ = {'LIGHT': box('LIGHT HORIZONTAL'), 'HEAVY': box('HEAVY HORIZONTA6HORIZ = {'LIGHT': box('LIGHT HORIZONTAL'), 'HEAVY': box('HEAVY HORIZONTA
>L')}>L')}
7VERT = {'LIGHT': box('LIGHT VERTICAL'), 'HEAVY': box('HEAVY VERTICAL')}7VERT = {'LIGHT': box('LIGHT VERTICAL'), 'HEAVY': box('HEAVY VERTICAL')}
8C_TL = {('LIGHT', 'LIGHT'): box('LIGHT DOWN AND RIGHT'), ('LIGHT', 'HEAV8C_TL = {('LIGHT', 'LIGHT'): box('LIGHT DOWN AND RIGHT'), ('LIGHT', 'HEAV
>Y'): box('DOWN LIGHT AND RIGHT HEAVY'), ('HEAVY', 'LIGHT'): box('DOWN HE>Y'): box('DOWN LIGHT AND RIGHT HEAVY'), ('HEAVY', 'LIGHT'): box('DOWN HE
>AVY AND RIGHT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY DOWN AND RIGHT')}>AVY AND RIGHT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY DOWN AND RIGHT')}
9C_TR = {('LIGHT', 'LIGHT'): box('LIGHT DOWN AND LEFT'), ('LIGHT', 'HEAVY9C_TR = {('LIGHT', 'LIGHT'): box('LIGHT DOWN AND LEFT'), ('LIGHT', 'HEAVY
>'): box('DOWN LIGHT AND LEFT HEAVY'), ('HEAVY', 'LIGHT'): box('DOWN HEAV>'): box('DOWN LIGHT AND LEFT HEAVY'), ('HEAVY', 'LIGHT'): box('DOWN HEAV
>Y AND LEFT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY DOWN AND LEFT')}>Y AND LEFT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY DOWN AND LEFT')}
10C_BL = {('LIGHT', 'LIGHT'): box('LIGHT UP AND RIGHT'), ('LIGHT', 'HEAVY'10C_BL = {('LIGHT', 'LIGHT'): box('LIGHT UP AND RIGHT'), ('LIGHT', 'HEAVY'
>): box('UP LIGHT AND RIGHT HEAVY'), ('HEAVY', 'LIGHT'): box('UP HEAVY AN>): box('UP LIGHT AND RIGHT HEAVY'), ('HEAVY', 'LIGHT'): box('UP HEAVY AN
>D RIGHT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY UP AND RIGHT')}>D RIGHT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY UP AND RIGHT')}
11C_BR = {('LIGHT', 'LIGHT'): box('LIGHT UP AND LEFT'), ('LIGHT', 'HEAVY')11C_BR = {('LIGHT', 'LIGHT'): box('LIGHT UP AND LEFT'), ('LIGHT', 'HEAVY')
>: box('UP LIGHT AND LEFT HEAVY'), ('HEAVY', 'LIGHT'): box('UP HEAVY AND >: box('UP LIGHT AND LEFT HEAVY'), ('HEAVY', 'LIGHT'): box('UP HEAVY AND 
>LEFT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY UP AND LEFT')}>LEFT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY UP AND LEFT')}
12V_MID_L = {('LIGHT', 'LIGHT'): box('LIGHT VERTICAL AND RIGHT'), ('LIGHT'12V_MID_L = {('LIGHT', 'LIGHT'): box('LIGHT VERTICAL AND RIGHT'), ('LIGHT'
>, 'HEAVY'): box('VERTICAL LIGHT AND RIGHT HEAVY'), ('HEAVY', 'LIGHT'): b>, 'HEAVY'): box('VERTICAL LIGHT AND RIGHT HEAVY'), ('HEAVY', 'LIGHT'): b
>ox('VERTICAL HEAVY AND RIGHT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY VER>ox('VERTICAL HEAVY AND RIGHT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY VER
>TICAL AND RIGHT')}>TICAL AND RIGHT')}
13V_MID_R = {('LIGHT', 'LIGHT'): box('LIGHT VERTICAL AND LEFT'), ('LIGHT',13V_MID_R = {('LIGHT', 'LIGHT'): box('LIGHT VERTICAL AND LEFT'), ('LIGHT',
> 'HEAVY'): box('VERTICAL LIGHT AND LEFT HEAVY'), ('HEAVY', 'LIGHT'): box> 'HEAVY'): box('VERTICAL LIGHT AND LEFT HEAVY'), ('HEAVY', 'LIGHT'): box
>('VERTICAL HEAVY AND LEFT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY VERTIC>('VERTICAL HEAVY AND LEFT LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY VERTIC
>AL AND LEFT')}>AL AND LEFT')}
14CROSS = {('LIGHT', 'LIGHT'): box('LIGHT VERTICAL AND HORIZONTAL'), ('LIG14CROSS = {('LIGHT', 'LIGHT'): box('LIGHT VERTICAL AND HORIZONTAL'), ('LIG
>HT', 'HEAVY'): box('VERTICAL LIGHT AND HORIZONTAL HEAVY'), ('HEAVY', 'LI>HT', 'HEAVY'): box('VERTICAL LIGHT AND HORIZONTAL HEAVY'), ('HEAVY', 'LI
>GHT'): box('VERTICAL HEAVY AND HORIZONTAL LIGHT'), ('HEAVY', 'HEAVY'): b>GHT'): box('VERTICAL HEAVY AND HORIZONTAL LIGHT'), ('HEAVY', 'HEAVY'): b
>ox('HEAVY VERTICAL AND HORIZONTAL')}>ox('HEAVY VERTICAL AND HORIZONTAL')}
15T_UP = {('LIGHT', 'LIGHT'): box('LIGHT UP AND HORIZONTAL'), ('LIGHT', 'H15T_UP = {('LIGHT', 'LIGHT'): box('LIGHT UP AND HORIZONTAL'), ('LIGHT', 'H
>EAVY'): box('UP LIGHT AND HORIZONTAL HEAVY'), ('HEAVY', 'LIGHT'): box('U>EAVY'): box('UP LIGHT AND HORIZONTAL HEAVY'), ('HEAVY', 'LIGHT'): box('U
>P HEAVY AND HORIZONTAL LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY UP AND HO>P HEAVY AND HORIZONTAL LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY UP AND HO
>RIZONTAL')}>RIZONTAL')}
16T_DOWN = {('LIGHT', 'LIGHT'): box('LIGHT DOWN AND HORIZONTAL'), ('LIGHT'16T_DOWN = {('LIGHT', 'LIGHT'): box('LIGHT DOWN AND HORIZONTAL'), ('LIGHT'
>, 'HEAVY'): box('DOWN LIGHT AND HORIZONTAL HEAVY'), ('HEAVY', 'LIGHT'): >, 'HEAVY'): box('DOWN LIGHT AND HORIZONTAL HEAVY'), ('HEAVY', 'LIGHT'): 
>box('DOWN HEAVY AND HORIZONTAL LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY D>box('DOWN HEAVY AND HORIZONTAL LIGHT'), ('HEAVY', 'HEAVY'): box('HEAVY D
>OWN AND HORIZONTAL')}>OWN AND HORIZONTAL')}
1717
18def main():18def main():
19    text = sys.stdin.readline().rstrip('\n')19    text = sys.stdin.readline().rstrip('\n')
20    params = sys.stdin.readline().split()20    params = sys.stdin.readline().split()
21    width = int(params[0])21    width = int(params[0])
22    v_thick = params[1]22    v_thick = params[1]
23    h_thick = params[2]23    h_thick = params[2]
24    combo = (v_thick, h_thick)24    combo = (v_thick, h_thick)
25    inner = width - 225    inner = width - 2
26    words = text.split()26    words = text.split()
27    lines_words = []27    lines_words = []
28    curr = []28    curr = []
29    curr_len = 029    curr_len = 0
30    for w in words:30    for w in words:
31        L = len(w)31        L = len(w)
32        if not curr:32        if not curr:
33            curr = [w]33            curr = [w]
34            curr_len = L34            curr_len = L
35        else:35        else:
36            needed = curr_len + L + len(curr)36            needed = curr_len + L + len(curr)
37            if needed <= inner:37            if needed <= inner:
38                curr.append(w)38                curr.append(w)
39                curr_len += L39                curr_len += L
40            else:40            else:
41                lines_words.append(curr)41                lines_words.append(curr)
42                curr = [w]42                curr = [w]
43                curr_len = L43                curr_len = L
44    if curr:44    if curr:
45        lines_words.append(curr)45        lines_words.append(curr)
46    line_infos = []46    line_infos = []
47    vert_sets = []47    vert_sets = []
48    for line in lines_words:48    for line in lines_words:
49        k = len(line)49        k = len(line)
50        lens = [len(w) for w in line]50        lens = [len(w) for w in line]
51        base = sum(lens) + (k - 1)51        base = sum(lens) + (k - 1)
52        extra = inner - base52        extra = inner - base
53        lens[-1] += extra53        lens[-1] += extra
54        vpos = {0}54        vpos = {0}
55        pos = 155        pos = 1
56        for wlen in lens[:-1]:56        for wlen in lens[:-1]:
57            pos += wlen57            pos += wlen
58            vpos.add(pos)58            vpos.add(pos)
59            pos += 159            pos += 1
60        vpos.add(width - 1)60        vpos.add(width - 1)
61        vert_sets.append(vpos)61        vert_sets.append(vpos)
62        line_infos.append((line, lens))62        line_infos.append((line, lens))
63    v_char = VERT[v_thick]63    v_char = VERT[v_thick]
6464
65    def make_hrow(up_set, down_set):65    def make_hrow(up_set, down_set):
66        row = []66        row = []
67        for x in range(width):67        for x in range(width):
68            up = x in up_set68            up = x in up_set
69            down = x in down_set69            down = x in down_set
70            if x == 0:70            if x == 0:
71                if up and down:71                if up and down:
72                    ch = V_MID_L[combo]72                    ch = V_MID_L[combo]
73                elif down and (not up):73                elif down and (not up):
74                    ch = C_TL[combo]74                    ch = C_TL[combo]
75                elif up and (not down):75                elif up and (not down):
76                    ch = C_BL[combo]76                    ch = C_BL[combo]
77                else:77                else:
78                    ch = HORIZ[h_thick]78                    ch = HORIZ[h_thick]
79            elif x == width - 1:79            elif x == width - 1:
80                if up and down:80                if up and down:
81                    ch = V_MID_R[combo]81                    ch = V_MID_R[combo]
82                elif down and (not up):82                elif down and (not up):
83                    ch = C_TR[combo]83                    ch = C_TR[combo]
84                elif up and (not down):84                elif up and (not down):
85                    ch = C_BR[combo]85                    ch = C_BR[combo]
86                else:86                else:
87                    ch = HORIZ[h_thick]87                    ch = HORIZ[h_thick]
88            elif up and down:88            elif up and down:
89                ch = CROSS[combo]89                ch = CROSS[combo]
90            elif down and (not up):90            elif down and (not up):
91                ch = T_DOWN[combo]91                ch = T_DOWN[combo]
92            elif up and (not down):92            elif up and (not down):
93                ch = T_UP[combo]93                ch = T_UP[combo]
94            else:94            else:
95                ch = HORIZ[h_thick]95                ch = HORIZ[h_thick]
96            row.append(ch)96            row.append(ch)
97        return ''.join(row)97        return ''.join(row)
98    out_lines = []98    out_lines = []
99    out_lines.append(make_hrow(set(), vert_sets[0]))99    out_lines.append(make_hrow(set(), vert_sets[0]))
100    for i, (words_line, cell_widths) in enumerate(line_infos):100    for i, (words_line, cell_widths) in enumerate(line_infos):
101        line = [v_char]101        line = [v_char]
102        for w, wlen in zip(words_line, cell_widths):102        for w, wlen in zip(words_line, cell_widths):
103            line.append(w.ljust(wlen))103            line.append(w.ljust(wlen))
104            line.append(v_char)104            line.append(v_char)
105        out_lines.append(''.join(line))105        out_lines.append(''.join(line))
106        if i + 1 < len(line_infos):106        if i + 1 < len(line_infos):
107            out_lines.append(make_hrow(vert_sets[i], vert_sets[i + 1]))107            out_lines.append(make_hrow(vert_sets[i], vert_sets[i + 1]))
108        else:108        else:
109            out_lines.append(make_hrow(vert_sets[i], set()))109            out_lines.append(make_hrow(vert_sets[i], set()))
110    print('\n'.join(out_lines))110    print('\n'.join(out_lines))
111if __name__ == '__main__':111if __name__ == '__main__':
112    main()112    main()
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op