結果
問題 | No.648 お や す み |
ユーザー | Yuki_Utaai |
提出日時 | 2018-05-27 23:58:27 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,995 bytes |
コンパイル時間 | 293 ms |
コンパイル使用メモリ | 87,200 KB |
実行使用メモリ | 93,696 KB |
最終ジャッジ日時 | 2023-09-12 19:48:37 |
合計ジャッジ時間 | 51,088 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 106 ms
77,476 KB |
testcase_01 | AC | 328 ms
82,336 KB |
testcase_02 | AC | 101 ms
77,368 KB |
testcase_03 | AC | 421 ms
82,888 KB |
testcase_04 | AC | 454 ms
84,552 KB |
testcase_05 | AC | 103 ms
77,676 KB |
testcase_06 | AC | 474 ms
84,960 KB |
testcase_07 | AC | 478 ms
84,304 KB |
testcase_08 | AC | 480 ms
84,944 KB |
testcase_09 | AC | 102 ms
77,748 KB |
testcase_10 | AC | 574 ms
87,468 KB |
testcase_11 | AC | 567 ms
86,708 KB |
testcase_12 | AC | 553 ms
86,372 KB |
testcase_13 | AC | 555 ms
87,304 KB |
testcase_14 | AC | 532 ms
86,680 KB |
testcase_15 | AC | 567 ms
87,116 KB |
testcase_16 | AC | 590 ms
86,768 KB |
testcase_17 | AC | 551 ms
86,012 KB |
testcase_18 | AC | 544 ms
86,864 KB |
testcase_19 | AC | 562 ms
86,656 KB |
testcase_20 | AC | 173 ms
79,640 KB |
testcase_21 | WA | - |
testcase_22 | AC | 226 ms
80,548 KB |
testcase_23 | AC | 172 ms
79,412 KB |
testcase_24 | AC | 138 ms
79,140 KB |
testcase_25 | AC | 193 ms
80,192 KB |
testcase_26 | AC | 126 ms
78,320 KB |
testcase_27 | AC | 171 ms
79,676 KB |
testcase_28 | AC | 417 ms
85,856 KB |
testcase_29 | AC | 144 ms
79,120 KB |
testcase_30 | AC | 459 ms
85,068 KB |
testcase_31 | AC | 435 ms
84,896 KB |
testcase_32 | AC | 432 ms
84,504 KB |
testcase_33 | AC | 436 ms
85,296 KB |
testcase_34 | AC | 432 ms
84,600 KB |
testcase_35 | AC | 477 ms
85,872 KB |
testcase_36 | AC | 504 ms
85,900 KB |
testcase_37 | AC | 446 ms
84,864 KB |
testcase_38 | AC | 441 ms
84,788 KB |
testcase_39 | AC | 479 ms
86,116 KB |
testcase_40 | AC | 440 ms
84,532 KB |
testcase_41 | AC | 460 ms
85,644 KB |
testcase_42 | AC | 437 ms
84,768 KB |
testcase_43 | AC | 437 ms
84,448 KB |
testcase_44 | AC | 436 ms
84,968 KB |
testcase_45 | AC | 450 ms
85,232 KB |
testcase_46 | AC | 479 ms
85,888 KB |
testcase_47 | AC | 434 ms
85,076 KB |
testcase_48 | AC | 431 ms
85,112 KB |
testcase_49 | AC | 451 ms
84,680 KB |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | WA | - |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | AC | 985 ms
92,092 KB |
testcase_61 | AC | 964 ms
92,800 KB |
testcase_62 | AC | 959 ms
91,932 KB |
testcase_63 | AC | 964 ms
92,204 KB |
testcase_64 | AC | 955 ms
92,156 KB |
testcase_65 | AC | 953 ms
92,140 KB |
testcase_66 | AC | 959 ms
91,640 KB |
testcase_67 | AC | 971 ms
92,040 KB |
testcase_68 | AC | 957 ms
92,612 KB |
testcase_69 | AC | 947 ms
91,848 KB |
testcase_70 | AC | 890 ms
93,696 KB |
testcase_71 | AC | 918 ms
93,156 KB |
testcase_72 | AC | 983 ms
93,004 KB |
testcase_73 | AC | 972 ms
92,604 KB |
testcase_74 | AC | 977 ms
92,056 KB |
testcase_75 | AC | 975 ms
92,196 KB |
testcase_76 | AC | 958 ms
91,720 KB |
testcase_77 | WA | - |
testcase_78 | WA | - |
testcase_79 | WA | - |
testcase_80 | WA | - |
testcase_81 | WA | - |
testcase_82 | WA | - |
testcase_83 | WA | - |
ソースコード
import random #--------粒 子 群 最 適 化------------------------------ #評価関数: def criterion(x, y): z=-abs(k-(x*(x+1))/2) if x<0: z=-10000000000 return z #粒子の位置の更新を行う関数 def update_position(x, y, vx, vy): new_x = x + vx new_y = y + vy return new_x, new_y #粒子の速度の更新を行う関数 def update_velocity(x, y, vx, vy, p, g, w=1, ro_max=1,v_max=100): #パラメーターroはランダムに与える ro1 = random.uniform(0, ro_max) ro2 = random.uniform(0, ro_max) #粒子速度の更新を行う new_vx = int(w * vx + ro1 * (p[0] - x) + ro2 * (g[0] - x)) if abs(new_vx)>v_max: new_vx=int(v_max*new_vx/abs(new_vx)) new_vy = w * vy + ro1 * (p[1] - y) + ro2 * (g[1] - y) return new_vx, new_vy def main(): N = 1000 #粒子の数 x_min, x_max = 0, k y_min, y_max = 0, 0 #粒子位置, 速度, パーソナルベスト, グローバルベストの初期化を行う ps = [[random.randint(x_min, x_max), random.uniform(y_min, y_max)] for i in range(N)] vs = [[0.0, 0.0] for i in range(N)] personal_best_positions = list(ps) personal_best_scores = [criterion(p[0], p[1]) for p in ps] best_particle = personal_best_scores.index(max(personal_best_scores)) global_best_position = personal_best_positions[best_particle] T = 600 #世代数(ループの回数) for t in range(T): for n in range(N): x, y = ps[n][0], ps[n][1] vx, vy = vs[n][0], vs[n][1] p = personal_best_positions[n] #粒子の位置の更新を行う new_x, new_y = update_position(x, y, vx, vy) ps[n] = [new_x, new_y] #粒子の速度の更新を行う new_vx, new_vy = update_velocity(new_x, new_y, vx, vy, p, global_best_position) vs[n] = [new_vx, new_vy] #評価値を求め, パーソナルベストの更新を行う score = criterion(new_x, new_y) if score > personal_best_scores[n]: personal_best_scores[n] = score personal_best_positions[n] = [new_x, new_y] #グローバルベストの更新を行う best_particle = personal_best_scores.index(max(personal_best_scores)) global_best_position = personal_best_positions[best_particle] if k==(global_best_position[0]*(global_best_position[0]+1))//2: print("YES") print(int(global_best_position[0])) exit() #最適解 # print(max(personal_best_scores), global_best_position) return max(personal_best_scores), global_best_position[0], global_best_position[1] #-------------------------------------------------------------- k=int(input()) best=-100000000000000 xx=0 yy=0 for i in range(3): kouho_best, kouho_x, kouho_y=main() if best>kouho_best: best=kouho_best xx=kouho_x yy=kouho_y print("NO")