Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- contests = [1146]
- # [1, rank_start] get tshirts with no random
- # [rank_start + 1, rand_end] get random tshirts
- rank_start = 1
- rank_end = 250
- n_random_tshirts = 25
- def is_eligible(contest, party_name, rank, points, problems, last_submission_time):
- return (1 <= rank_start and rank <= rank_end)
- def get_party_name(party):
- if 'teamName' in party:
- return party['teamName']
- else:
- return party['members'][0]['handle']
- class Party:
- def __init__(self, contest, name, rank, points, last_submission_time):
- self.contest = contest
- self.name = name
- self.rank = rank
- self.points = points
- self.last_submission_time = last_submission_time
- def __lt__(self, other):
- if self.contest != other.contest:
- return self.contest < other.contest
- if self.rank != other.rank:
- return self.rank < other.rank
- if self.last_submission_time != other.last_submission_time:
- return self.last_submission_time < other.last_submission_time
- if self.name != other.name:
- return self.name < other.name
- return False
- eligible = []
- for contest in contests:
- rows_to_fetch = 20000
- r = requests.get('https://codeforces.com/api/contest.standings?contestId=%d&from=1&count=%d&showUnofficial=false' % (contest, rows_to_fetch))
- if r.status_code != 200 or r.json()['status'] != 'OK':
- print('Error: failed to fetch results of contest %d.' % contest)
- exit()
- results = r.json()['result']['rows']
- if len(results) == rows_to_fetch:
- print('Error: results are too long in contest %d, increase limit.' % contest)
- exit()
- for row in results:
- party_name = get_party_name(row['party'])
- rank = row['rank']
- points = row['points']
- problems = 0
- last_submission_time = 0
- for problem in row['problemResults']:
- if problem['points'] > 0:
- problems += 1
- last_submission_time = max(last_submission_time, problem['bestSubmissionTimeSeconds'])
- if is_eligible(contest, party_name, rank, points, problems, last_submission_time):
- eligible.append(Party(contest, party_name, rank, points, last_submission_time))
- eligible = sorted(eligible)
- for i in range(1, len(eligible)):
- if not eligible[i - 1] < eligible[i]:
- print('Error: unable to sort eligible at positions {} {}.'.format(i, i, i + 1))
- exit()
- print('Eligible for tshirts are:')
- for idx, party in enumerate(eligible):
- print('{} {} {} {} {}'.format(idx + 1, party.contest, party.rank, party.name, party.last_submission_time))
- seed = eligible[0].points
- print('Total %d eligible, seed is %d.' % (len(eligible), seed))
- import subprocess
- testlib_rand = subprocess.run(['./randgen', str(seed), str(len(eligible)), str(rank_start - 1), str(n_random_tshirts)], stdout=subprocess.PIPE)
- winners = list(map(int, testlib_rand.stdout.split()))
- print()
- print('Winners are:')
- for place in winners:
- print('{} {} {} {}'.format(place, eligible[place - 1].contest, eligible[place - 1].rank, eligible[place - 1].name))
- print()
- print('| List place | Contest | Rank | Name |')
- print('|--|--|--|--|')
- for place in winners:
- print('| {} | {} | {} | [user:{}] |'.format(place, eligible[place - 1].contest, eligible[place - 1].rank, eligible[place - 1].name))
Advertisement
Add Comment
Please, Sign In to add comment