| Task: | Insert Whitespace |
| Sender: | bits pls |
| Submission time: | 2019-05-25 15:40:03 +0300 |
| Language: | Python3 |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.07 s | details |
| #2 | ACCEPTED | 0.07 s | details |
| #3 | ACCEPTED | 0.07 s | details |
| #4 | WRONG ANSWER | 0.07 s | details |
| #5 | TIME LIMIT EXCEEDED | -- | details |
| #6 | TIME LIMIT EXCEEDED | -- | details |
| #7 | TIME LIMIT EXCEEDED | -- | details |
| #8 | TIME LIMIT EXCEEDED | -- | details |
| #9 | TIME LIMIT EXCEEDED | -- | details |
| #10 | TIME LIMIT EXCEEDED | -- | details |
| #11 | TIME LIMIT EXCEEDED | -- | details |
| #12 | TIME LIMIT EXCEEDED | -- | details |
| #13 | TIME LIMIT EXCEEDED | -- | details |
Code
#n,h,W,p = 2,6,33,5
n,h,W,p = map(int, input().split())
s = """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.""".split("\n")
def maplines(l, li=0, o=[], s=0):
if len(l) == li: return [o]
out = []
for k in l[li].keys():
lenv = s + k
if lenv < h and h - lenv >= 2 or lenv % h == 0:
o1 = list(o)
o1.append(k)
for a in maplines(l, li+1, o1, lenv):
out.append(a)
elif lenv > h and lenv%h >= 2:
lenv = lenv - lenv//h * h
o1 = list(o)
o1.append(k)
for a in maplines(l, li+1, o1, lenv):
out.append(a)
return out
def addsp(w, wi=0, l=None, s=p):
#if l == None: l = [p]
if wi == len(w): return [l]
l.append(w[wi])
s += w[wi]
wi += 1
if s == W or wi == len(w):
l.append(0)
return addsp(w, wi, l, s=0)
elif s > W: return []
l2 = list(l)
s2 = s
l.append(1)
s += 1
if s == W:
return []
l.append(0)
return addsp(w, wi, l, s=0)
l2.append(2)
s2 += 2
lo = []
for add in addsp(w, wi, l, s):
lo.append(add)
if s2 != W:
#l2.append(0)
for add in addsp(w, wi, l2, s2):
lo.append(add)
return lo
def getout(l):
global dl
o = []
a = ""
for i in range(len(dl)):
o.append(dl[i][l[i]])
# print(o)
linecount = 0
for i in range(len(o)):
a += o[i].pop(0)*" "
isword = True
wordi = 0
for el in o[i]:
if el == 0:
a += "\n"
isword = True
linecount += 1
if linecount == h:
linecount = 0
a += "#\n"
continue
if isword:
a += prgs[i][wordi]
wordi += 1
else:
a += el * " "
isword = not isword
return a
prgs = []
dl = []
for _ in range(n):
prg = input().split()
# prg = s.pop(0).split()
prgs.append(prg)
# print("\n\n")
# print(prg)
pgrl = list(map(len, prg))
# print(pgrl)
pos = addsp(pgrl, l=[p])
# print(pos)
# print(p)
# input()
# if pos == []:
# print("IMPOSSIBLE")
d = {}
for P in pos:
c = P.count(0)
if c not in d:
d[c] = P
dl.append(d)
ans = maplines(dl)
if ans == []:
print("IMPOSSIBLE")
else:
print(getout(ans[0]).rstrip("\n#"))
#print(ans)
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 3 5 10 2 a a a a a a a a a a a a a a a ... |
| correct output |
|---|
| a a a a a a a a a a a a a a a a a a a a ... |
| user output |
|---|
| a a a a a a a a a a a a a a a a a a a a ... Truncated |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 3 6 10 2 a a a a a a a a a a a a a a a ... |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| IMPOSSIBLE |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 3 7 10 2 a a a a a a a a a a a a a a a ... |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| IMPOSSIBLE |
Test 4
Verdict: WRONG ANSWER
| input |
|---|
| 3 8 10 2 a a a a a a a a a a a a a a a ... |
| correct output |
|---|
| a a a a a a a a a a a a a a a a a a a a ... |
| user output |
|---|
| IMPOSSIBLE |
Test 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 5 10 80 4 Lorem ipsum dolor sit amet, co... |
| correct output |
|---|
| Lorem ipsum dolor sit amet... |
| user output |
|---|
| (empty) |
Test 6
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 5 10 70 4 Lorem ipsum dolor sit amet, co... |
| correct output |
|---|
| Lorem ipsum dolor sit amet... |
| user output |
|---|
| (empty) |
Test 7
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 5 10 60 4 Lorem ipsum dolor sit amet, co... |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| (empty) |
Test 8
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 55 20 80 4 Lorem ipsum dolor sit amet, co... |
| correct output |
|---|
| Lorem ipsum dolor sit ame... |
| user output |
|---|
| (empty) |
Test 9
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 55 20 80 6 Lorem ipsum dolor sit amet, co... |
| correct output |
|---|
| Lorem ipsum dolor sit... |
| user output |
|---|
| (empty) |
Test 10
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 55 20 80 8 Lorem ipsum dolor sit amet, co... |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| (empty) |
Test 11
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 3 43 37 34 aaa aaaaa aaaa a aa aa aa aaa ... |
| correct output |
|---|
| ... |
| user output |
|---|
| (empty) |
Test 12
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 4 50 73 12 aaaaa aa a aaa a aaa aaaa aaaa... |
| correct output |
|---|
| aaaaa aa a aaa ... |
| user output |
|---|
| (empty) |
Test 13
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 4 6 62 31 aa aaa aaa aa aaaaa aaa aaaaa ... |
| correct output |
|---|
| ... |
| user output |
|---|
| (empty) |
