Submission #350017

#TimeUsernameProblemLanguageResultExecution timeMemory
350017KirishinaPoi (IOI09_poi)C++14
45 / 100
673 ms16108 KiB

#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+2;
					else {
						campoAOrdenar=id;
						sort(empatadosProblemasresueltos.begin(),empatadosProblemasresueltos.end(),comparacion);
						r=posPhilipPorPuntos+buscarPorID(p,empatadosProblemasresueltos)+1;
					}
		}
	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 (stderr)

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 timeMemoryGrader output
Fetching results...