Submission #584102

# Submission time Handle Problem Language Result Execution time Memory
584102 2022-06-26T19:31:28 Z evening_g Poi (IOI09_poi) C++11
0 / 100
532 ms 19608 KB
/**
 * @file poi2.cpp
 * @author Blanca Huergo (https://blancahuergo.es)
 * @brief Solutions.pdf
 * @version 0.1
 * @date 2022-06-25
 * 
 */

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

using namespace std;

vector<int> points, solutions_per_problem, problems_solved;

/**
 * @brief Comparator to sort players according to the rules
 * returns
 *  true if `i` goes before `j`,
 *  else returns false
 * @param i 
 * @param j 
 * @return true 
 * @return false 
 */
bool compare(int i, int j) {
    if (points[i] > points[j])                      // if `i` has more points than `j`
        return true;                                // then `i` goes first

    else if (points[i] < points[j])                 // if `j` has more points than `i`
        return false;                               // then `j` goes first

                                                    // else, `i` and `j` have the same points
    if (problems_solved[i] > problems_solved[j])    // if `i` solved more problems than `j`
        return true;                                // then `i` goes first
    
    if (problems_solved[i] < problems_solved[j])    // if `j` solved more problems than `i`
        return false;                               // then `j` goes first

                                                    // if `i` and `j` have the same points
                                                    // and solved the same number of problems
    return i < j;                                   // then sort by their ID
}

/**
 * @brief Calculates the points of each player and sorts them
 * 
 * @param table 
 * @param players 
 */
void sort_players(vector< vector<int> > &table, vector<int> &players) {
    // get the number of tasks and players
    const int T = (int) table[0].size(), N = (int) players.size();

    // count the number of players that solved each task
    for (int i = 0; i < T; i++)
        for (int j = 0; j < N; j++)
            solutions_per_problem[i] += table[i][j];

    // for each task, calculate the points for each player
    for (int i = 0; i < N; i++)
        for (int j = 0; j < T; j++)
            if (table[i][j]) {
                points[i] += (N-solutions_per_problem[j]);
                problems_solved[i] ++;
            }
    
    // sort the players with custom compare function
    sort(players.begin(), players.end(), compare);
}

int main() {
    // DEFINE VARIABLES
    int N, T, P;

    cin >> N >> T >> P;

    vector< vector<int> > table(N, vector<int>(T));
    vector<int> players(N);

    points.assign(N, 0);
    problems_solved.assign(N, 0);
    solutions_per_problem.assign(T, 0);

    // READ DATA
    for (int i = 0; i < N; i++) {
        players[i] = i;             // assign players ID
        for (int j = 0; j < T; j++)
            cin >> table[i][j];     // read table data
    }
    
    sort_players(table, players);   // sort players

    for (int i = 0; i < N; i++)
        if (players[i] == P-1) {    // find Philip position
            cout << points[P-1] << " " << i+1 << "\n";
            break;
        }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Runtime error 1 ms 340 KB Execution killed with signal 11
3 Runtime error 1 ms 340 KB Execution killed with signal 11
4 Incorrect 1 ms 212 KB Output isn't correct
5 Runtime error 1 ms 340 KB Execution killed with signal 11
6 Incorrect 1 ms 212 KB Output isn't correct
7 Runtime error 1 ms 340 KB Execution killed with signal 11
8 Incorrect 1 ms 212 KB Output isn't correct
9 Runtime error 3 ms 468 KB Execution killed with signal 11
10 Incorrect 5 ms 340 KB Output isn't correct
11 Runtime error 17 ms 1280 KB Execution killed with signal 11
12 Incorrect 28 ms 1100 KB Output isn't correct
13 Runtime error 82 ms 5068 KB Execution killed with signal 11
14 Incorrect 143 ms 3668 KB Output isn't correct
15 Runtime error 195 ms 12476 KB Execution killed with signal 11
16 Incorrect 247 ms 6696 KB Output isn't correct
17 Runtime error 339 ms 19608 KB Execution killed with signal 11
18 Incorrect 436 ms 11012 KB Output isn't correct
19 Incorrect 489 ms 14476 KB Output isn't correct
20 Incorrect 532 ms 16044 KB Output isn't correct