-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemp.py
More file actions
106 lines (87 loc) · 3.65 KB
/
temp.py
File metadata and controls
106 lines (87 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import requests
import sys
import random
def get_user_attempted_problems(username):
url = f"https://codeforces.com/api/user.status?handle={username}"
response = requests.get(url).json()
if response.get("status") != "OK":
print("Error al obtener las sumisiones del usuario.")
sys.exit(1)
attempted = set()
for submission in response["result"]:
problem = submission.get("problem", {})
key = (problem.get("contestId"), problem.get("index"))
attempted.add(key)
return attempted
def get_gym_contest_with_icpc():
url = "https://codeforces.com/api/contest.list?gym=true"
response = requests.get(url).json()
if response.get("status") != "OK":
print("Error al obtener la lista de concursos.")
sys.exit(1)
contests = response.get("result", [])
gym_icpc_contests = [contest for contest in contests if "ICPC" in contest.get("type", "") and contest.get("difficulty", "") == 4]
contest = gym_icpc_contests[- int(random.randint(1, 100))]
return contest
def get_contest_problems(contest_id):
url = f"https://codeforces.com/api/contest.standings?contestId={contest_id}&from=1&count=1"
response = requests.get(url).json()
if response.get("status") != "OK":
print("Error al obtener los standings del contest.")
sys.exit(1)
problems = response.get("result", {}).get("problems", [])
return problems
def get_contest_status_submissions(contest_id):
url = f"https://codeforces.com/api/contest.status?contestId={contest_id}&from=1&count=100000&showUnofficial=true"
response = requests.get(url).json()
if response.get("status") != "OK":
print("Error al obtener las sumisiones del contest.")
sys.exit(1)
submissions = response.get("result", [])
return submissions
def compute_accepted_counts(submissions):
accepted_counts = {}
for sub in submissions:
if sub.get("verdict") == "OK":
prob = sub.get("problem", {})
key = (prob.get("contestId"), prob.get("index"))
members = sub.get("author", {}).get("members", [])
if members:
user = members[0].get("handle")
else:
user = None
if not user:
continue
if key not in accepted_counts:
accepted_counts[key] = set()
accepted_counts[key].add(user)
counts = {key: len(users) for key, users in accepted_counts.items()}
return counts
def main():
username = "RauPro"
user_attempted = get_user_attempted_problems(username)
contest = get_gym_contest_with_icpc()
contest_id = contest.get("id")
print(f"GYM: {contest.get('name')} (ID: {contest_id})")
problems = get_contest_problems(contest_id)
candidate_problems = []
for prob in problems:
key = (prob.get("contestId"), prob.get("index"))
if key not in user_attempted:
candidate_problems.append(prob)
if not candidate_problems:
print("No se encontraron problemas candidatos que cumplan con los criterios.")
return
submissions = get_contest_status_submissions(contest_id)
accepted_counts = compute_accepted_counts(submissions)
for prob in candidate_problems:
key = (prob.get("contestId"), prob.get("index"))
prob["solvedCount"] = accepted_counts.get(key, 0)
candidate_problems_sorted = sorted(candidate_problems, key=lambda p: p["solvedCount"], reverse=True)
top_4 = candidate_problems_sorted[:4]
print("\nTop 4:")
for p in top_4:
print(
f"{p['contestId']}{p['index']} - {p['name']}, Accepted Rate: {p['solvedCount']})")
if __name__ == "__main__":
main()