fork(1) download
  1. import numpy as np
  2. import hashlib
  3.  
  4. # 추첨 인원수
  5. winner_num = 5
  6. # BOJ 연습란을 텍스트로 긁어오면 됩니다 (랭킹, 아이디, A, B, C, ... 맨 윗줄 제외하고)
  7. info = """
  8. 1 glnthd02 1 / 72 1 / 75 1 / 81 1 / 88 1 / 111 5 / 559 4 / 4287 7 / 5273
  9. 2 bwgreen 1 / 241 1 / 245 1 / 265 3 / 315 1 / 299 13 / 807 1 / 6267 7 / 8439
  10. 3 gandori3 1 / 3548 3 / 2185 2 / 3489 1 / 1669 3 / 3562 1 / 5620 6 / 4608 7 / 24681
  11. 4 dksalsdn0226 5 / 216 1 / 144 4 / 229 3 / 232 3 / 271 13 / 1507 0 / -- 6 / 2599
  12. 5 aarhrl2 2 / 5010 1 / 4972 1 / 4967 5 / 3186 5 / 3399 14 / 5159 0 / -- 6 / 26693
  13. 6 hms0510 1 / 155 1 / 161 1 / 185 2 / 243 2 / 517 0 / -- 0 / -- 5 / 1261
  14. 7 silhighver 1 / 3701 1 / 3709 0 / -- 1 / 3614 1 / 3677 3 / 4483 0 / -- 5 / 19184
  15. 8 jnn54 3 / 6007 1 / 5986 1 / 6013 1 / 6025 3 / 6391 0 / -- 0 / -- 5 / 30422
  16. 9 haerizian 2 / 6373 1 / 6360 1 / 6387 1 / 6401 1 / 6413 0 / -- 0 / -- 5 / 31934
  17. 10 bakbakwanwan 1 / 528 1 / 558 1 / 590 1 / 603 0 / -- 0 / -- 0 / -- 4 / 2279
  18. 11 sjyoon1101 2 / 422 1 / 431 1 / 510 3 / 1694 0 / -- 2 / -- 0 / -- 4 / 3057
  19. 12 psh030122 5 / 195 2 / 1529 1 / 1528 1 / 3070 0 / -- 0 / -- 0 / -- 4 / 6322
  20. 13 ansinbin000 3 / 4384 2 / 4492 1 / 4563 2 / 4628 0 / -- 0 / -- 0 / -- 4 / 18067
  21. 14 gebalsebal 3 / 3135 1 / 3105 0 / -- 3 / 3184 3 / -- 0 / -- 0 / -- 3 / 9424
  22. 15 yuujeong0816 1 / 6302 1 / 1979 1 / -- 1 / 1824 5 / -- 0 / -- 0 / -- 3 / 10105
  23. 16 harrysooin 2 / 3137 1 / 4757 2 / 5914 0 / -- 0 / -- 0 / -- 0 / -- 3 / 13808
  24. 17 choiseoo 2 / 1733 1 / 3188 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 4921
  25. 18 upncol 0 / -- 0 / -- 0 / -- 2 / 4143 6 / 4276 0 / -- 0 / -- 2 / 8419
  26. 19 kdy06 1 / 5798 2 / 6254 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 2 / 12052
  27. 20 aerae 0 / -- 1 / 37 2 / -- 0 / -- 0 / -- 0 / -- 0 / -- 1 / 37
  28. 21 jung0722 1 / 124 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 1 / 124
  29. 22 likescape 1 / 544 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 0 / -- 1 / 544
  30. """
  31. info = info.splitlines(keepends = True)
  32. if info[0] == "\n": info.pop(0)
  33.  
  34. # 랜덤 시드
  35. mod = 4294967296 # 2^32
  36. seed_string = "250917"
  37. random_seed = int.from_bytes(hashlib.sha256(seed_string.encode()).digest(), 'big') % mod
  38. np.random.seed(random_seed)
  39.  
  40. participants = {}
  41. for participant in info:
  42. participant = participant.split('\t')
  43. user = participant[1]
  44. corrects = int(participant[-1].split(' / ')[0])
  45. if user in participants:
  46. participants[user] = max(participants[user], corrects + 3)
  47. else: participants[user] = corrects + 3
  48.  
  49. # 추첨 명단 제외 리스트
  50. except_list = ['aerae','likescape']
  51. for except_user in except_list:
  52. try:
  53. participants.pop(except_user)
  54. except:
  55. pass
  56.  
  57. # 추첨 확률 설정
  58. winner_percent = [0] * len(participants)
  59. correct_problems_sum = sum(participants.values())
  60.  
  61. for i, corrects in enumerate(list(participants.values())):
  62. winner_percent[i] = corrects / correct_problems_sum
  63.  
  64. print(f'랜덤 시드: {seed_string}')
  65. print(f'{len(participants)}명 {list(participants.keys())}')
  66. # print(f'맞은 문제 개수: {list(participants.values())}')
  67. # print(f'확률: {winner_percent}')
  68.  
  69. # 당첨자
  70. winner = np.random.choice(list(participants.keys()), winner_num, replace = False, p = winner_percent) \
  71. if winner_num < len(participants) else list(participants.keys())
  72. winner.sort()
  73. print(f'당첨자: {winner}')# your code goes here
Success #stdin #stdout 0.78s 41416KB
stdin
Standard input is empty
stdout
랜덤 시드: 250917
20명 ['glnthd02', 'bwgreen', 'gandori3', 'dksalsdn0226', 'aarhrl2', 'hms0510', 'silhighver', 'jnn54', 'haerizian', 'bakbakwanwan', 'sjyoon1101', 'psh030122', 'ansinbin000', 'gebalsebal', 'yuujeong0816', 'harrysooin', 'choiseoo', 'upncol', 'kdy06', 'jung0722']
당첨자: ['ansinbin000' 'dksalsdn0226' 'haerizian' 'hms0510' 'sjyoon1101']