/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 95ms 3.832 MiB
#3 Accepted 95ms 3.809 MiB
#4 Accepted 96ms 3.91 MiB
#5 Accepted 95ms 3.738 MiB
#6 Accepted 96ms 3.836 MiB
#7 Accepted 90ms 3.754 MiB
#8 Accepted 80ms 3.723 MiB
#9 Accepted 72ms 3.754 MiB
#10 Accepted 64ms 3.844 MiB
#11 Accepted 48ms 2.805 MiB
#12 Accepted 14ms 1.215 MiB

Code

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>

using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<tuple<int, int, int>> participants; // (score, contest_type, index)
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        participants.emplace_back(x, 0, 0); // Main contest participants
    }
    int m;
    cin >> m;
    vector<int> ans(m);
    for(int i = 0; i < m; i++) {
        int x;
        cin >> x;
        participants.emplace_back(x, 1, i); // Replay contest participants
    }
    sort(participants.begin(), participants.end(), [](const auto& lhs, const auto& rhs) {
        int lhs_score = get<0>(lhs);
        int lhs_type = get<1>(lhs);
        int lhs_index = get<2>(lhs);
        int rhs_score = get<0>(rhs);
        int rhs_type = get<1>(rhs);
        int rhs_index = get<2>(rhs);
        if(lhs_score != rhs_score)
            return lhs_score > rhs_score; // Higher scores first
        if(lhs_type != rhs_type)
            return lhs_type < rhs_type; // Main contest before replay contest
        if(lhs_type == 1) // Both are replay participants
            return lhs_index < rhs_index; // Earlier index first
        return false; // Both are main participants with same score, keep their order
    });
    for(int i = 0; i < participants.size(); i++) {
        int score = get<0>(participants[i]);
        int contest_type = get<1>(participants[i]);
        int index = get<2>(participants[i]);
        if(contest_type == 1) {
            ans[index] = i + 1; // Positions are 1-based
        }
    }
    for(int i = 0; i < m; i++) {
        cout << ans[i];
        if(i != m - 1) cout << ' ';
    }
    // Do not print extra newline as per problem statement
}

int main() {
    solve();
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1049 Combined scoreboard
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-05 22:52:26
Judged At
2024-11-11 02:40:03
Judged By
Score
100
Total Time
96ms
Peak Memory
3.91 MiB