Greedy beats DP this time...
I tried several DP solutions first, but all failed with RE\TLE. If you 'feel' the problem, Greedy should be working:
(A solution from discussion)
def getPivot(n): while n > 0: if n % 3 == 0: break; else: n -= 5 return n T = input() for i in xrange(T): N = int(input()) pivot = getPivot(N) if pivot < 0: print -1 else: str = '' repeat = pivot / 3 while repeat > 0: str += '555' repeat -= 1 repeat = (N - pivot) / 5 while repeat > 0: str += '33333' repeat -= 1 print str
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步