Submission #923541

#TimeUsernameProblemLanguageResultExecution timeMemory
923541ZygnoPoi (IOI09_poi)C++17
100 / 100
504 ms24580 KiB
#include <bits/stdc++.h>
using namespace std;

struct contestant {
    int id;
    int score;
    int solvedTasks;
    int finalRank;
    contestant(int _id, int _score, int _solvedTasks, int _finalRank) {
        id = _id;
        score = _score;
        solvedTasks = _solvedTasks;
        finalRank = _finalRank;
    }
    contestant() {
        id = -1;
        score = -1;
        solvedTasks = -1;
        finalRank = -1;
    }
};

vector<vector<int>> scoreInput;
vector<int> taskScore;
vector<contestant> contestantScore;

bool customCompare(contestant a, contestant b) {
    if(a.score > b.score) return true;
    if(a.score < b.score) return false;
    if(a.solvedTasks > b.solvedTasks) return true;
    if(a.solvedTasks < b.solvedTasks) return false;
    return a.id < b.id;
}

int main(){
    
    int n; // Number of contestants
    int t; // Number of tasks
    int p; // Philip’s ID was P    
    
    cin >> n >> t >> p;

    //Read the task scores
    for(int i = 0; i < n; i++){ // Contestant
        scoreInput.push_back(std::vector<int>()); // Add a new row
        for(int j = 0; j < t; j++){ // Task
            int a;
            cin >> a;
            scoreInput[i].push_back(a); // Add an element to the first row
        }
    }

    //Calculate the task scores
    for(int j = 0; j < t; j++){ // Task
        int points = 0;
        for(int i = 0; i < n; i++){ // Contestant
            if(scoreInput[i][j] == 0) points++;
        }
        taskScore.push_back(points);
    }

    //Calculate the contestant scores
    for(int i = 0; i < n; i++){ // Contestant
        int points = 0;
        int solvedTasks = 0;
        for(int j = 0; j < t; j++){ // Task
            if(scoreInput[i][j] == 1){
                points += taskScore[j];
                solvedTasks++;
            }
        }
        contestant temp = contestant(i+1, points, solvedTasks, -1);
        contestantScore.push_back(temp);
    }
    
    //Sort the contestant scores
    sort(contestantScore.begin(), contestantScore.end(), customCompare);
    for(int i = 0; i < n; i++){
        contestantScore[i].finalRank = i+1;
    }

    //Sort the contestant scores by id
    sort(contestantScore.begin(), contestantScore.end(), [](contestant a, contestant b) {
        return a.id < b.id;
    });

    cout << contestantScore[p-1].score << " " << contestantScore[p-1].finalRank << endl;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...