CSES - Aalto Competitive Programming 2024 - wk12 - Wed - Results
Submission details
Task:Text Alignment
Sender:arnxxau
Submission time:2024-11-27 17:46:46 +0200
Language:Python3 (PyPy3)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.04 sdetails
#2ACCEPTED0.04 sdetails
#3ACCEPTED0.04 sdetails
#4ACCEPTED0.04 sdetails
#5ACCEPTED0.04 sdetails
#6ACCEPTED0.04 sdetails
#7ACCEPTED0.04 sdetails
#8ACCEPTED0.04 sdetails
#9ACCEPTED0.04 sdetails
#10ACCEPTED0.04 sdetails
#11ACCEPTED0.04 sdetails
#12ACCEPTED0.05 sdetails
#13ACCEPTED0.05 sdetails

Code

def fullJustify(words, maxWidth):
    res, cur, num_of_letters = [], [], 0
    for w in words:
        if num_of_letters + len(w) + len(cur) > maxWidth:
            for i in range(maxWidth - num_of_letters):
                cur[i%(len(cur)-1 or 1)] += ' '
            res.append(''.join(cur))
            cur, num_of_letters = [], 0
        cur += [w]
        num_of_letters += len(w)

    return res + [' '.join(cur).ljust(maxWidth)]

s = input()
s = s.split(' ')

for x in fullJustify(s, 50):
    print(x)

Test details

Test 1

Verdict: ACCEPTED

input
zsyadhzdg ke irkyowki nflwfanr...

correct output
zsyadhzdg                     ...

user output
zsyadhzdg ke irkyowki nflwfanr...

Test 2

Verdict: ACCEPTED

input
eayoylmki efsqdhm qqvnrd npesu...

correct output
eayoylmki                     ...

user output
eayoylmki      efsqdhm      qq...

Test 3

Verdict: ACCEPTED

input
bsvhdnoxlxad f bclsa llq hjrmp...

correct output
bsvhdnoxlxad                  ...

user output
bsvhdnoxlxad f bclsa llq hjrmp...

Test 4

Verdict: ACCEPTED

input
xoezwspspfdzfasgxlqu f wjzpekp...

correct output
xoezwspspfdzfasgxlqu          ...

user output
xoezwspspfdzfasgxlqu      f   ...

Test 5

Verdict: ACCEPTED

input
bwvfj zmcpktjnmhzevcqtvlg twch...

correct output
bwvfj                         ...

user output
bwvfj  zmcpktjnmhzevcqtvlg  tw...

Test 6

Verdict: ACCEPTED

input
yifvbbjczpcnpknimq lttkngpeqsz...

correct output
yifvbbjczpcnpknimq            ...

user output
yifvbbjczpcnpknimq            ...

Test 7

Verdict: ACCEPTED

input
fu lzslzio ncbkga nrwuijkbrh x...

correct output
fu                            ...

user output
fu  lzslzio ncbkga nrwuijkbrh ...

Test 8

Verdict: ACCEPTED

input
azgwjnvgkapltkknwm odostksvqal...

correct output
azgwjnvgkapltkknwm            ...

user output
azgwjnvgkapltkknwm    odostksv...

Test 9

Verdict: ACCEPTED

input
j mmadidafwkd dckim iwjy bzsso...

correct output
j                             ...

user output
j    mmadidafwkd    dckim   iw...

Test 10

Verdict: ACCEPTED

input
barm sykc faxmvycwxs cnxuwpetq...

correct output
barm                          ...

user output
barm      sykc      faxmvycwxs...

Test 11

Verdict: ACCEPTED

input
ltwg ns j axhacysdjhrpzymwxae ...

correct output
ltwg                          ...

user output
ltwg  ns  j  axhacysdjhrpzymwx...

Test 12

Verdict: ACCEPTED

input
pgwvxzeztltppuuq siarhxbs mjmr...

correct output
pgwvxzeztltppuuq              ...

user output
pgwvxzeztltppuuq    siarhxbs  ...

Test 13

Verdict: ACCEPTED

input
xurwjadifyf iijoofrunig zadrff...

correct output
xurwjadifyf                   ...

user output
xurwjadifyf         iijoofruni...