QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#811339 | #9573. Social Media | xtqqwq | WA | 15ms | 10572kb | Python3 | 2.2kb | 2024-12-12 18:08:26 | 2024-12-12 18:08:27 |
Judging History
answer
def maximize_visibility(test_cases):
results = []
for n, m, k, friends, comments in test_cases:
# Current friends set
friend_set = set(friends)
# Initialize visibility map
visibility_map = {}
for a, b in comments:
if a not in visibility_map:
visibility_map[a] = set()
visibility_map[a].add(b)
# Calculate visible comments for current friends
visible_comments = 0
for a, b in comments:
if a in friend_set and b in friend_set:
visible_comments += 1
# Compute individual user impacts
user_impact = {}
for a, b in comments:
if a not in friend_set or b not in friend_set:
if a not in friend_set:
user_impact[a] = user_impact.get(a, 0) + 1
if b not in friend_set:
user_impact[b] = user_impact.get(b, 0) + 1
# Sort users by impact
sorted_impact = sorted(user_impact.items(), key=lambda x: -x[1])
# Best impact scores
best_impact = [0, 0] # Top 2 impacts
best_users = []
for user, impact in sorted_impact:
if len(best_users) < 2:
best_users.append(user)
best_impact[len(best_users) - 1] = impact
else:
break
# Calculate max visibility
max_visibility = visible_comments # Case 1
# Case 2: Add one new friend
if len(best_users) > 0:
max_visibility = max(max_visibility, visible_comments + best_impact[0])
# Case 3: Add two new friends
if len(best_users) > 1:
max_visibility = max(max_visibility, visible_comments + best_impact[0] + best_impact[1])
results.append(max_visibility)
return results
# Input and example usage
T = int(input())
test_cases = []
for _ in range(T):
n, m, k = map(int, input().split())
friends = list(map(int, input().split()))
comments = [tuple(map(int, input().split())) for _ in range(m)]
test_cases.append((n, m, k, friends, comments))
results = maximize_visibility(test_cases)
print("\n".join(map(str, results)))
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 15ms
memory: 10572kb
input:
5 4 12 7 5 7 3 6 3 6 2 2 1 4 2 4 1 3 7 6 4 1 5 4 1 1 1 1 2 1 3 7 2 7 6 2 4 1 2 3 2 2 5 5 4 2 6 4 6 2 6 1 1 2 1 1 2 2 1 2 1 2 1 2 2 1 100 24 11 11 24
output:
15 5 1 1 1
result:
wrong answer 1st numbers differ - expected: '9', found: '15'