fork(3) download
  1. # http://c...content-available-to-author-only...e.com/a/87445/34718
  2. # https://r...content-available-to-author-only...l.it/CikZ/1 OR http://i...content-available-to-author-only...e.com/AkejPS
  3.  
  4.  
  5. """
  6. n,w,h=input()
  7. s=[""]*h
  8. for x in 1,2:
  9. exec"for i in range(h):l=len(s[i]+`n`)<=w;s[i]+=`n`*l;n-=l\n"*w;s=[r.replace(" ","")for r in map(lambda x:`x`[2::5],zip(*[r.ljust(w)for r in s]))];w,h=h,w
  10. print s
  11. """
  12.  
  13. # less golfed
  14. def f(n,w,h):
  15. s=[""]*h
  16. for x in 1,2:
  17. for j in[0]*w:
  18. for i in range(h):l=len(s[i]+`n`)<=w;s[i]+=`n`*l;n-=l
  19. s=[r.ljust(w)for r in s]
  20. s=map(lambda x:`x`[2::5],zip(*s))
  21. s=[r.replace(' ','')for r in s]
  22. w,h=h,w
  23. print"\n".join(s)
  24.  
  25. f(1,1,1);print
  26. f(6,6,1);print
  27. f(6,2,3);print
  28. f(10,1,11);print
  29. f(11,13,1);print
  30. f(27,9,5);print
  31. f(200,41,12);print
  32.  
  33. # additional test cases
  34. f(100,2,96);print
  35. f(99,3,63);print
  36. f(183,21,21);print
  37.  
Success #stdin #stdout 0.01s 8968KB
stdin
200,41,12
stdout
1

654321

63
52
41

1
0
9
8
7
6
5
4
3
2
1

1110987654321

272217127
262116116
252015105
241914942
231813831

20018817616415214012811610492806856443220
19918717516315113912711510391796755433119
19818617416215013812611410290786654423018
19718517316114913712511310189776553412917
19618417216014813612411210088766452402816
19518317115914713512311199877563513927158
19418217015814613412211098867462503826147
19318116915714513312110997857361493725136
19218016815614413212010896847260483624125
19117916715514313111910795837159473523114
19017816615414213011810694827058463422103
18917716515314112911710593816957453321921

19
09
09
97
89
95
69
93
49
91
28
99
08
87
88
85
68
83
48
81
27
89
07
77
87
75
67
73
47
71
26
79
06
67
86
65
66
63
46
61
25
69
05
57
85
55
65
53
45
51
24
59
04
47
84
45
64
43
44
41
23
49
03
37
83
35
63
33
43
31
22
39
02
27
82
25
62
23
42
21
21
29
01
17
81
15
61
13
41
11
29
17
05
83
62
41

993
986
973
965
953
944
933
923
913
902
893
881
873
860
852
849
832
828
812
807
792
786
772
765
752
744
732
723
712
702
692
681
672
660
651
649
631
628
611
607
591
586
571
565
551
544
531
523
511
502
491
481
471
460
459
448
437
426
415
404
393
382
371

183162141120997857361
182161140119987756355
181160139118977655341
180159138117967554334
179158137116957453321
178157136115947352313
177156135114937251301
176155134113927150292
175154133112917049281
174153132111906948271
173152131110896847261
172151130109886746250
171150129108876645249
170149128107866544238
169148127106856443227
168147126105846342216
167146125104836241205
166145124103826140194
165144123102816039183
164143122101805938172
163142121100795837161