QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#747062#9573. Social MediaxtqqwqWA 55ms3680kbC++173.6kb2024-11-14 16:15:572024-11-14 16:15:58

Judging History

你现在查看的是最新测评结果

  • [2024-11-14 16:15:58]
  • 评测
  • 测评结果:WA
  • 用时:55ms
  • 内存:3680kb
  • [2024-11-14 16:15:57]
  • 提交

answer

#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <set>

using namespace std;

int main() {
    int T;
    cin >> T;
    vector<int> results;

    while (T--) {
        int n, m, k;
        cin >> n >> m >> k;

        unordered_set<int> friends;
        for (int i = 0; i < n; i++) {
            int friend_id;
            cin >> friend_id;
            friends.insert(friend_id);
        }

        vector<pair<int, int>> comments;
        for (int i = 0; i < m; i++) {
            int a, b;
            cin >> a >> b;
            comments.emplace_back(a, b);
        }

        int initial_visible_count = 0;
        unordered_map<int, int> single_friend_gain;
        unordered_map<int, set<int>> both_needed;

        for (const auto& comment : comments) {
            int a = comment.first;
            int b = comment.second;

            if (friends.count(a) && friends.count(b)) {
                initial_visible_count++;
            } else if (friends.count(a)) {
                single_friend_gain[b]++;
            } else if (friends.count(b)) {
                single_friend_gain[a]++;
            } else {
                both_needed[a].insert(b);
                both_needed[b].insert(a);
            }
        }

        // Step 1: Find the maximum visibility increase by adding one friend
        int max_single_addition = 0;
        for (const auto& [user, gain] : single_friend_gain) {
            max_single_addition = max(max_single_addition, gain);
        }

        // Step 2: Find the maximum visibility increase by adding two friends
        int max_double_addition = 0;

        // Case 1: Two friends from `single_friend_gain`
        vector<int> single_friend_gains;
        for (const auto& [user, gain] : single_friend_gain) {
            single_friend_gains.push_back(gain);
        }
        sort(single_friend_gains.rbegin(), single_friend_gains.rend());
        if (single_friend_gains.size() >= 2) {
            max_double_addition = single_friend_gains[0] + single_friend_gains[1];
        } else if (!single_friend_gains.empty()) {
            max_double_addition = single_friend_gains[0];
        }

        // Case 2: Two friends from `both_needed`
        for (const auto& [user1, needed_set1] : both_needed) {
            for (const int& user2 : needed_set1) {
                if (user1 < user2) {
                    // Count comments visible by adding both user1 and user2
                    int additional_visible = 0;
                    unordered_set<int> added_friends = {user1, user2};

                    // Count visibility from single additions for user1 and user2
                    additional_visible += single_friend_gain[user1] + single_friend_gain[user2];

                    // Count visibility from comments requiring both user1 and user2
                    for (const auto& [a, b] : comments) {
                        if (added_friends.count(a) && added_friends.count(b) && !friends.count(a) && !friends.count(b)) {
                            additional_visible++;
                        }
                    }

                    max_double_addition = max(max_double_addition, additional_visible);
                }
            }
        }

        // Step 3: Compute the maximum visible comments
        int max_comments_visible = initial_visible_count + max(max_single_addition, max_double_addition);
        results.push_back(max_comments_visible);
    }

    for (int result : results) {
        cout << result << endl;
    }

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

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:

9
5
1
1
1

result:

ok 5 number(s): "9 5 1 1 1"

Test #2:

score: -100
Wrong Answer
time: 55ms
memory: 3680kb

input:

10000
19 12 20
8 12 1 5 11 7 17 13 19 6 3 9 10 15 14 20 4 18 16
4 11
7 1
8 4
16 19
1 13
15 2
16 2
8 7
3 15
11 13
5 20
18 14
17 14 20
2 9 1 12 8 11 10 17 18 16 3 15 5 14 20 13 7
15 10
3 2
5 16
7 8
6 1
6 4
18 16
1 8
4 1
20 6
6 9
4 15
7 5
14 9
1 3 18
9
15 18
17 15
11 14
7 19 7
3 1 2 5 6 4 7
5 1
4 5
3 1...

output:

12
14
1
19
5
5
1
11
19
4
3
10
4
0
4
19
15
2
18
4
17
5
1
2
5
17
3
2
6
15
6
3
5
4
4
7
3
7
4
1
16
15
2
3
6
12
12
7
6
8
8
6
8
11
16
1
4
9
8
14
2
6
19
19
16
8
20
14
8
12
7
9
6
8
2
17
9
5
5
3
6
6
20
8
13
11
10
5
3
5
3
1
8
5
8
11
7
14
10
9
8
11
7
9
5
2
8
14
10
5
3
5
5
10
1
6
8
16
5
3
19
1
4
8
8
10
3
2
1
15...

result:

wrong answer 5th numbers differ - expected: '6', found: '5'