結果

問題 No.775 tatyamと素数大富豪(hard)
ユーザー 👑 kmjpkmjp
提出日時 2018-12-22 01:19:35
言語 PyPy2
(7.3.15)
結果
TLE  
実行時間 -
コード長 744 bytes
コンパイル時間 1,805 ms
コンパイル使用メモリ 76,592 KB
実行使用メモリ 103,740 KB
最終ジャッジ日時 2024-04-22 02:47:14
合計ジャッジ時間 8,305 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 144 ms
98,488 KB
testcase_01 AC 143 ms
91,272 KB
testcase_02 AC 140 ms
91,268 KB
testcase_03 AC 140 ms
91,152 KB
testcase_04 AC 140 ms
91,816 KB
testcase_05 AC 139 ms
91,424 KB
testcase_06 AC 148 ms
91,564 KB
testcase_07 AC 155 ms
91,960 KB
testcase_08 AC 153 ms
91,904 KB
testcase_09 AC 176 ms
94,736 KB
testcase_10 AC 171 ms
94,768 KB
testcase_11 AC 143 ms
91,156 KB
testcase_12 AC 146 ms
91,040 KB
testcase_13 AC 161 ms
94,364 KB
testcase_14 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math

import random

C=set()


def dfs(id,s,cur):
	global K
	global prev
	global C
	if id==N:
		if cur!=prev:
			C.add(cur)
			if len(C)>2*K:
				C=list(C)
				C.sort()
				C.reverse()
				for c in C[:K]:
					print(c)
				sys.exit(0)
			
			prev = cur
		return
		
	for i in range(N):
		if i not in s:
			if i>0 and A[i]==A[i-1] and (i-1) not in s:
				continue
			s.add(i)
			dfs(id+1,s,cur+A[i])
			s.remove(i)

N,K=map(int,raw_input().strip().split(" "))
A=raw_input().strip().split(" ")
prev=""

for x in range(N):
	for i in range(N-1):
		if A[i]+A[i+1] < A[i+1]+A[i] or (A[i]+A[i+1] == A[i+1]+A[i] and A[i]<A[i+1]):
			A[i],A[i+1]=A[i+1],A[i]

dfs(0,set(),"")


C=list(C)
C.sort()
C.reverse()
for c in C[:K]:
	print(c)


0