結果

問題 No.775 tatyamと素数大富豪(hard)
ユーザー 👑 kmjpkmjp
提出日時 2018-12-22 01:15:25
言語 PyPy2
(7.3.15)
結果
WA  
実行時間 -
コード長 1,451 bytes
コンパイル時間 1,653 ms
コンパイル使用メモリ 76,544 KB
実行使用メモリ 101,632 KB
最終ジャッジ日時 2024-04-22 02:46:50
合計ジャッジ時間 8,279 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
96,768 KB
testcase_01 AC 148 ms
91,008 KB
testcase_02 WA -
testcase_03 AC 147 ms
90,880 KB
testcase_04 AC 149 ms
91,264 KB
testcase_05 AC 149 ms
91,648 KB
testcase_06 AC 152 ms
91,520 KB
testcase_07 AC 162 ms
91,776 KB
testcase_08 AC 154 ms
92,160 KB
testcase_09 AC 178 ms
94,848 KB
testcase_10 AC 166 ms
92,288 KB
testcase_11 AC 148 ms
91,520 KB
testcase_12 AC 155 ms
91,648 KB
testcase_13 WA -
testcase_14 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math

import random
 
def is_Prime(n):
    """
    Miller-Rabin primality test.
 
    A return value of False means n is certainly not prime. A return value of
    True means n is very likely a prime.
    """
    if n!=int(n):
        return False
    n=int(n)
    #Miller-Rabin test for prime
    if n==0 or n==1 or n==4 or n==6 or n==8 or n==9:
        return False
 
    if n==2 or n==3 or n==5 or n==7:
        return True
    s = 0
    d = n-1
    while d%2==0:
        d>>=1
        s+=1
    assert(2**s * d == n-1)
 
    def trial_composite(a):
        if pow(a, d, n) == 1:
            return False
        for i in range(s):
            if pow(a, 2**i * d, n) == n-1:
                return False
        return True  
 
    for i in range(12):#number of trials 
        a = random.randrange(2, n)
        if trial_composite(a):
            return False
 
    return True

def dfs(id,s,cur):
	global K
	global prev
	if id==N:
		if cur!=prev:
			print(cur)
			K -= 1
			if K==0:
				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(),"")




0