====== Secret Sharing ====== ===== 풀이 ===== * [[ps:problems:boj:16496]]의 응용 문제이다. * [[ps:problems:boj:16496]] 에서의 핵심은, 수들을 늘어놓아서 가장 큰 수를 만들기 위해서는 수들을 문자열로 처리해서 정렬하되 비교함수를 x+y """Solution code for "BOJ 2385. Secret Sharing". - Problem link: https://www.acmicpc.net/problem/2385 - Solution link: http://www.teferi.net/ps/problems/boj/2385 """ import functools def main(): N = int(input()) # pylint: disable=unused-variable shares = input().split() comp_key = functools.cmp_to_key(lambda x, y: -1 if (x + y) < (y + x) else 1) zero_shares = [x for x in shares if x[0] == '0'] nonzero_shares = [x for x in shares if x[0] != '0'] if not nonzero_shares: print('INVALID') return zero_part = ''.join(sorted(zero_shares, key=comp_key)) z = zero_part[:5] first_part = min( nonzero_shares, key=functools.cmp_to_key( lambda x, y: -1 if (x + z + y) < (y + z + x) else 1)) nonzero_shares.remove(first_part) last_part = ''.join(sorted(nonzero_shares, key=comp_key)) print(first_part + zero_part + last_part) if __name__ == '__main__': main() {{tag>BOJ ps:problems:boj:플래티넘_2}}