# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
584102 | evening_g | Poi (IOI09_poi) | C++11 | 532 ms | 19608 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* @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 |
---|---|---|---|---|
Fetching results... |