I don’t think that these constraints allow some really bad solutions to pass, so for me, it’s OK.
The main reason why I put such a constraint into a problem is that I don’t know to want to do this task impossible for some languages (I don’t know whether sth like python will be ok to output 1e7 characters in 2 seconds). Maybe it could be done with sth like “output number of 1, number of 2, and so on in optimal answer”, but I don’t think that this way the problem becomes more interesting.
As I see, basically any solution with normal complexity passed, and those which have bad one can be easily fixed to put into TLE (if the idea behind them is correct).
Also, it is easy to prove (by construction) that the answer is never -1 for any positive integer N.
About adding testcase, I am not so familiar with that on codechef.
Solve this with similar DP. My proof: #include <bits/stdc++.h>using namespace std; typedef long long LL;typede - Pastebin.com
Why am i getting wrong answer as i have used same approach as yours…
solution - CodeChef: Practical coding for everyone
oooh i was missing tht … my bad btw thanks for your reply
Since the solution is allways a relatively small number the simple brute force greedy solution works.
I implemented it after did not getting the dp solutions right… one can see the fragments in my code.
https://www.codechef.com/viewsolution/27683718
You can just try every value of N up to 1’000’000, and keep track of the highest, like I did 
I have done exactly same
What a way to avoid plagiarism. Copy someone’s code, introduce unnecessary variables like sid, momo, chale_chalo and you are done.
what is sid & momo tho…?
bro my idea is similar to yours and a used the fact that maximum count of digit 2-8 are 5
but why is my code partially correct CodeChef: Practical coding for everyone
when i precalculate 5 digits but when i precalculate upto 6 digits that its getting accepted see CodeChef: Practical coding for everyone
This solution fails on the testcase:
1
957520
Edit:
Actually, both of your solutions do - weak testcases causes the latter to get AC, I suppose ![]()
oh thanks actually this is not my solution i was just going through the successful submissions and i wanted to find the idea behind this one (cause it looked simple XD),
and i tweaked it a little bit , is this one CodeChef: Practical coding for everyone getting correct??, this is the original one
That gets the correct answer for that particular testcase, at least - it’s far too slow to do an exhaustive check, though 
okay thanks
If anyone’s interested, here’s a program that exhaustively computes the results for all 1 \le N \le 1000000; because of the large size of the output, I use a simple compression scheme: the code -
1xA+B
means “write out the digit 1 A times, then write out B” (NB: B will be empty if N is square).
Sample (the last 10 entries):
N: 999991 leading-1's-compressed-result: 1x999988+222 sum: 1000000( = 1000 x 1000)
N: 999992 leading-1's-compressed-result: 1x999991+3 sum: 1000000( = 1000 x 1000)
N: 999993 leading-1's-compressed-result: 1x999967+39999999999999999999999999 sum: 1002001( = 1001 x 1001)
N: 999994 leading-1's-compressed-result: 1x999992+22 sum: 1000000( = 1000 x 1000)
N: 999995 leading-1's-compressed-result: 1x999968+229999999999999999999999999 sum: 1002001( = 1001 x 1001)
N: 999996 leading-1's-compressed-result: 1x999969+378889999999999999999999999 sum: 1002001( = 1001 x 1001)
N: 999997 leading-1's-compressed-result: 1x999996+2 sum: 1000000( = 1000 x 1000)
N: 999998 leading-1's-compressed-result: 1x999972+29999999999999999999999999 sum: 1002001( = 1001 x 1001)
N: 999999 leading-1's-compressed-result: 1x999972+277899999999999999999999999 sum: 1002001( = 1001 x 1001)
N: 1000000 leading-1's-compressed-result: 1x1000000+ sum: 1000000( = 1000 x 1000)
Takes about a second or so to process all 1000000 values, though the 86MB of output takes a few seconds longer ![]()
Subtask-2, task-10 probably has the case where output is -1, but not sure
In given constrain there is no any number which output is -1.
Can you please elaborate this? How is it 27 by inspection?