# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
350018 |
2021-01-18T22:19:52 Z |
Kirishina |
Poi (IOI09_poi) |
C++14 |
|
691 ms |
16108 KB |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct datosConcursante {
int id;
int puntos;
int problemasResueltos;
};
enum TipoCampo {id, puntos, problemasResueltos};
TipoCampo campoAOrdenar;
bool comparacion(const datosConcursante& a, const datosConcursante& b)
{
bool bReturn;
switch (campoAOrdenar) {
case id : bReturn = a.id < b.id; break;
case puntos: bReturn = a.puntos > b.puntos; break;
case problemasResueltos: bReturn = a.problemasResueltos > b.problemasResueltos; break;
}
return bReturn;
}
int buscarPorID(int p, vector<datosConcursante>& V) {
int i=0;
bool encontrado=false;
while(!encontrado && (i<V.size())){
if (V[i].id==p) encontrado=true;
else i++;
}
return i;
}
bool igual(datosConcursante a, datosConcursante b,TipoCampo campo){
bool bIgual=false;
switch (campo) {
case id : bIgual = (a.id == b.id); break;
case puntos: bIgual = (a.puntos == b.puntos); break;
case problemasResueltos: bIgual = (a.problemasResueltos == b.problemasResueltos); break;
}
return bIgual;
}
/*
* Devuelve un vector de datosConcursante por los que estan empatados por el valor pasado en el 3 parámetro
*/
vector <datosConcursante> buscarEmpatados(int pos, vector<datosConcursante>& V, TipoCampo campo) {
//Comprobamos posibles empates
vector <datosConcursante> empatados;
empatados.push_back(V[pos]);
int i=pos;
while ( (i>0) && igual(V[i-1],V[pos], campo)){
empatados.push_back(V[i-1]);
i--;
}
i=pos;
while ( (i<V.size()) && igual(V[i+1],V[pos],campo) ){
empatados.push_back(V[i+1]);
i++;
}
return empatados;
}
int ranking(int p, vector<datosConcursante>& V) {
int r=-1;
campoAOrdenar=puntos;
sort(V.begin(),V.end(),comparacion);
int posPhilipPorPuntos=buscarPorID(p,V);
vector <datosConcursante> empatadosPuntos;
empatadosPuntos=buscarEmpatados(posPhilipPorPuntos,V,puntos);
if (empatadosPuntos.size()==1) r = posPhilipPorPuntos+1;
else{
// Hay empates
vector <datosConcursante> empatadosProblemasresueltos;;
int posPhilipPorProblemasresueltos=buscarPorID(p,empatadosPuntos);
empatadosProblemasresueltos=buscarEmpatados(posPhilipPorProblemasresueltos,empatadosPuntos,problemasResueltos);
if (empatadosProblemasresueltos.size()==1) r = posPhilipPorPuntos+posPhilipPorProblemasresueltos+1;
else {
campoAOrdenar=id;
sort(empatadosProblemasresueltos.begin(),empatadosProblemasresueltos.end(),comparacion);
r=posPhilipPorPuntos+buscarPorID(p,empatadosProblemasresueltos)+1 + empatadosPuntos.size()-empatadosProblemasresueltos.size();
}
}
return r;
}
int main() {
int N,T,P; // N: Nº concursantes , T: Nº tareas, P: ID Philip
vector <int> puntosTareas; // Valor em puntos de cada tarea i 0=<i<=T-1
cin >> N >> T >> P;
vector <datosConcursante> dc(N);
int mCT[N][T]; // Matriz concursantes x Tareas
puntosTareas.assign(T,N); // Inicialmente cada tarea tendrá el total de puntos e
// iremos restando para cada concursante que la haya realizado
int tareaRealizada;
for(int concursante=0; concursante<N;++concursante){
for(int tarea=0; tarea<T;++tarea){
cin>>tareaRealizada;
mCT[concursante][tarea]=tareaRealizada;
puntosTareas[tarea]-=tareaRealizada;
dc[concursante].problemasResueltos+=tareaRealizada;
}
}
for(int concursante=0; concursante<N;++concursante){
dc[concursante].id=concursante+1;
for(int tarea=0; tarea<T;++tarea){
dc[concursante].puntos += mCT[concursante][tarea]*puntosTareas[tarea];
}
}
cout<<dc[P-1].puntos << " " << ranking(P,dc) << '\n' ;
return 0;
}
Compilation message
poi.cpp: In function 'int buscarPorID(int, std::vector<datosConcursante>&)':
poi.cpp:33:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<datosConcursante>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | while(!encontrado && (i<V.size())){
| ~^~~~~~~~~
poi.cpp: In function 'std::vector<datosConcursante> buscarEmpatados(int, std::vector<datosConcursante>&, TipoCampo)':
poi.cpp:70:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<datosConcursante>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | while ( (i<V.size()) && igual(V[i+1],V[pos],campo) ){
| ~^~~~~~~~~
poi.cpp: In function 'bool comparacion(const datosConcursante&, const datosConcursante&)':
poi.cpp:27:9: warning: 'bReturn' may be used uninitialized in this function [-Wmaybe-uninitialized]
27 | return bReturn;
| ^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
3 ms |
364 KB |
Output is correct |
10 |
Correct |
6 ms |
364 KB |
Output is correct |
11 |
Correct |
21 ms |
748 KB |
Output is correct |
12 |
Correct |
35 ms |
1132 KB |
Output is correct |
13 |
Incorrect |
104 ms |
2796 KB |
Output isn't correct |
14 |
Incorrect |
152 ms |
3692 KB |
Output isn't correct |
15 |
Incorrect |
258 ms |
6380 KB |
Output isn't correct |
16 |
Correct |
283 ms |
6636 KB |
Output is correct |
17 |
Correct |
421 ms |
9708 KB |
Output is correct |
18 |
Correct |
474 ms |
10988 KB |
Output is correct |
19 |
Incorrect |
621 ms |
14572 KB |
Output isn't correct |
20 |
Correct |
691 ms |
16108 KB |
Output is correct |