ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 2385 |
문제명 | Secret Sharing |
레벨 | 플래티넘 2 |
분류 |
그리디 |
시간복잡도 | O(mnlogn) |
인풋사이즈 | n<=100, m<=5 |
사용한 언어 | Python |
제출기록 | 31908KB / 100ms |
최고기록 | 52ms |
해결날짜 | 2021/06/01 |
"""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()