제출 #584102

#제출 시각아이디문제언어결과실행 시간메모리
584102evening_gPoi (IOI09_poi)C++11
0 / 100
532 ms19608 KiB
/** * @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 timeMemoryGrader output
Fetching results...