結果
問題 | No.458 異なる素数の和 |
ユーザー | jensen |
提出日時 | 2021-01-15 13:54:41 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,692 ms / 2,000 ms |
コード長 | 1,007 bytes |
コンパイル時間 | 154 ms |
コンパイル使用メモリ | 10,936 KB |
実行使用メモリ | 363,676 KB |
最終ジャッジ日時 | 2023-08-17 04:03:45 |
合計ジャッジ時間 | 11,290 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 20 ms
8,088 KB |
testcase_01 | AC | 458 ms
109,656 KB |
testcase_02 | AC | 729 ms
140,920 KB |
testcase_03 | AC | 153 ms
30,524 KB |
testcase_04 | AC | 163 ms
37,404 KB |
testcase_05 | AC | 1,360 ms
303,740 KB |
testcase_06 | AC | 615 ms
133,400 KB |
testcase_07 | AC | 25 ms
8,724 KB |
testcase_08 | AC | 1,358 ms
306,748 KB |
testcase_09 | AC | 55 ms
14,948 KB |
testcase_10 | AC | 18 ms
7,992 KB |
testcase_11 | AC | 1,692 ms
363,676 KB |
testcase_12 | AC | 16 ms
8,004 KB |
testcase_13 | AC | 17 ms
8,100 KB |
testcase_14 | AC | 17 ms
8,176 KB |
testcase_15 | AC | 16 ms
8,116 KB |
testcase_16 | AC | 92 ms
20,960 KB |
testcase_17 | AC | 18 ms
8,164 KB |
testcase_18 | AC | 18 ms
8,196 KB |
testcase_19 | AC | 18 ms
8,060 KB |
testcase_20 | AC | 19 ms
8,080 KB |
testcase_21 | AC | 17 ms
8,056 KB |
testcase_22 | AC | 16 ms
8,124 KB |
testcase_23 | AC | 17 ms
8,180 KB |
testcase_24 | AC | 17 ms
8,172 KB |
testcase_25 | AC | 17 ms
8,048 KB |
testcase_26 | AC | 17 ms
8,196 KB |
testcase_27 | AC | 593 ms
127,236 KB |
testcase_28 | AC | 1,673 ms
356,128 KB |
testcase_29 | AC | 39 ms
11,452 KB |
testcase_30 | AC | 348 ms
81,312 KB |
ソースコード
import math def is_prime(n): if n == 1: return False for k in range(2, int(math.sqrt(n)) + 1): if n % k == 0: return False return True def find(l,iter,a): for i in range(iter,len(l)): if(l[i]>=a): break return i n=int(input()) pris=[] prisum=[] for i in range(2,n+1): if(is_prime(i)==True): pris.append(i) suum=0 for i in range(0,len(pris)): suum+=pris[i] prisum.append(suum) x=len(pris) f=[[0]*x for i in range(n)] if(n==1): print(-1) elif(n==2 or n==3): print(1) elif(n==4): print(-1) elif(n>4): f[1][0]=1 f[2][1]=1 ite=0 for i in range(4,n): ite=find(prisum,ite,i+1) for j in range(ite,min(ite+3,x)): if(i+1==pris[j]): f[i][j]=1 else: z=max(f[i-pris[j]][:j]) if(z>0): f[i][j]=z+1 mv=max(f[n-1]) if(mv==0): print(-1) else: print(mv)