## 10258 - Contest Scoreboard

Moderator: Board moderators

devious
New poster
Posts: 13
Joined: Wed Feb 22, 2006 1:26 am
EDIT: Accepted
Last edited by devious on Sat Oct 20, 2007 12:53 pm, edited 1 time in total.

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Try this:

Code: Select all

``````1

3 1 11 C
3 1 17 I``````

Code: Select all

``3 1 17``
Darko

devious
New poster
Posts: 13
Joined: Wed Feb 22, 2006 1:26 am
...what a stupid mistake... Thank you. Its AC

NrmMyth
New poster
Posts: 3
Joined: Mon Mar 20, 2006 10:46 pm

### 10258 "Contest Scoreboard" - Runtime error clarifi

Hi.
I would be very grateful if somebody can find my error. I'm getting "Runtime Error (Invalid memory reference)"

Code: Select all

``````#define pb( x ) push_back( x )
#define mp( x, y ) make_pair( x, y )

void trunc() // truncates line until newline character
{
char c;
while( (c = getchar()) != '\n' );
};

void nullify( const set<int>& s, int mm[100+13][10+13] )
{
for( set<int>::iterator it = s.begin(); it != s.end(); ++it )
for( int i = 1; i < 10; ++i ) mm[*it][i] = INT_MIN;
};

// struct of results
struct Rank
{
int c;
int p;
int pt;

Rank( int a ): c(a), p(0), pt(0) {};
Rank( int a, int b, int d ): c(a), p(b), pt(d) {};

bool operator >( const Rank& r ) const
{
if( this->p > r.p ) return true;
else if( this->p < r.p ) return false;
else if( this->pt < r.pt ) return true;
else if( this->pt > r.pt ) return false;
else return this->c < r.c;
};
};

// prints results
void printScoreTable( const set<int>& s, int mm[100+13][10+13] )
{
vector<Rank> v;
for( set<int>::iterator it = s.begin(); it != s.end(); ++it )
{
Rank r(*it);
for( int i = 1; i < 10; ++i )
if( mm[*it][i] >= 0 )
{
++r.p;
r.pt += mm[*it][i];
}
v.pb( r );
}
sort( v.begin(), v.end(), greater<Rank>() );

for( int i = 0; i < v.size(); ++i ) printf( "%d %d %d\n", v[i].c, v[i].p, v[i].pt );
};

int main( void )
{
int mm[100+13][10+13];
for( int i = 0; i < 100+13; ++i )
for( int j = 0; j < 10; ++j ) mm[i][j] = INT_MIN;

set<int> co;
char str[128];

int cases;
scanf( "%d", &cases ); trunc(); trunc();

for( int x = 0; x < cases; ++x )
{
while( strlen( gets( str ) ) != 0 )
{
int a, b, c; char d;
sscanf( str, "%d %d %d %c", &a, &b, &c, &d );

co.insert( a );
if( d == 'I' && mm[a][b] < 0 ) mm[a][b] += 20; // netocni submitovi prije tocnoga
else if( d == 'C' && mm[a][b] < 0 ) mm[a][b] = mm[a][b] - INT_MIN  + c;
}

printScoreTable( co, mm ); if( x != cases-1 ) putchar( '\n' );
nullify( co, mm );
co.clear();
}

//system( "pause" );
return 0;
}``````
If you read all of this thanks again.

sakhassan
Experienced poster
Posts: 105
Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU

### 10258 Contest Scoreboard Getting WA?

I have tried every possible options .... But still getting WA
Can anybuddy help me in explain the whole thing clearly .. if i had missed something

gtbass
New poster
Posts: 1
Joined: Sun Oct 01, 2006 12:43 am
when gets(str) reaches the EOF, it returns 0, which is passed to strlen() as a null pointer. To fix, do this instead:

Code: Select all

``while(gets(str) && strlen(str)) {...}``

NrmMyth
New poster
Posts: 3
Joined: Mon Mar 20, 2006 10:46 pm
gtbass wrote:

Code: Select all

``while(gets(str) && strlen(str)) {...}``
Thank you.

nymo
Experienced poster
Posts: 149
Joined: Sun Jun 01, 2003 8:58 am
Location: :)

### SOME TEST CASES:

I 've got correct answers for all the test cases of the board. I ve made some cases and got correct answers, too... still WA. can somebody post some more test cases???
regards,
nymo

chaturvedi
New poster
Posts: 8
Joined: Mon Jul 10, 2006 9:31 am

### @nymo

Hi,
The same thing happened with me... The problem was that I was not giving the output after pressing CtrlD that is EOF (my program was terminating as soon as i pressed it)... But was giving output after pressing enter. Check for one more thing that is you are parsing a blank line after the no of test cases.. Hope this helps

hamedv
Learning poster
Posts: 98
Joined: Mon May 07, 2007 8:30 am
What's wrong with my code??

Code: Select all

``````#include <stdio.h>

struct team {
int number, solved, time;
bool submit, sp[10];
};

int t, l, i, num, minute, problem, L[5], j;
char s[100];
team teams[105], tmp;

int main()
{
scanf("%d", &t);
gets(s);
gets(s);
for (l = 0; l < t; l++)
{
if (l) puts("");
for (i = 0; i < 105; i++)
{
teams[i].submit = 0;
teams[i].number = i+1;
teams[i].solved = 0;
teams[i].time = 0;
for (j = 0; j < 10; j++)
teams[i].sp[j] = 0;
}
while(gets(s) && s[0])
{
sscanf(s, "%d%d%d%s", &num, &problem, &minute, &L);
num--;
if (L[0] == 'I')
{
teams[num].submit = 1;
if (!teams[num].sp[problem]) teams[num].time += 20;
}
if (L[0] == 'C')
{
teams[num].submit = 1;
if (!teams[num].sp[problem]) teams[num].solved++;
if (!teams[num].sp[problem]) teams[num].time += minute;
teams[num].sp[problem] = 1;
}
}
for (i = 0; i < 104; i++)
for (j = 0; j < 104; j++)
if (teams[j].submit < teams[j+1].submit)
{
tmp = teams[j];
teams[j] = teams[j+1];
teams[j+1] = tmp;
}
for (i = 0; i < 104; i++)
for (j = 0; j < 104; j++)
if (teams[j].solved < teams[j+1].solved)
{
tmp = teams[j];
teams[j] = teams[j+1];
teams[j+1] = tmp;
}
for (i = 0; i < 104; i++)
for (j = 0; j < 104; j++)
if ((teams[j].solved == teams[j+1].solved) && (teams[j].time > teams[j+1].time))
{
tmp = teams[j];
teams[j] = teams[j+1];
teams[j+1] = tmp;
}
for (i = 0; i < 105, teams[i].submit; i++)
printf("%d %d %d\n", teams[i].number, teams[i].solved, teams[i].time);
}
}
``````

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
Read the description again. You have missed some points. However, here is a case..

Input:

Code: Select all

``````1

1 2 10 I
3 1 10 I
1 2 11 C
3 1 11 C
1 4 20 I``````
Output:

Code: Select all

``````1 1 31
3 1 31``````
Hope it helps.
Ami ekhono shopno dekhi...
HomePage

carpaneses
New poster
Posts: 3
Joined: Sat Jun 30, 2007 5:52 pm
Location: Sao Paulo - Brasil
Hi EveryBody! I am submiting my program and receiving the follow message "Presentation Error". What is this?

Here is my code:

Code: Select all

``````#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

#define false 0
#define true !false

#define MAX(X,Y) ((X)>(Y)?(X):(Y))
#define MIN(X,Y) ((X)>(Y)?(Y):(X))

struct sVetor2 {
int *numDesafio;
int *acertou;
int n, tam;
};
typedef struct sVetor2 vetor2;

struct sVetor {
int *qtdeAcertos;
vetor2 *desafios;
int n, tam;
};
typedef struct sVetor vetor;

struct sVetor3 {
int *caso;
int n, tam;
};
typedef struct sVetor3 vetor3;

/* prototipo das funcoes definidas sobre vetor */
void inicializa(vetor *s, int t);
void inicializa2(vetor2 *s, int t);
void inicializa3(vetor3 *s, int t);
int tamanho(vetor *s);

void Ordena(vetor *);

#define DEBUG(x)

int main(int argc, char *argv[])
{

vetor3 Campeonatos;
vetor2 DesafioAux;

int ehPrimeira = true;

char linha[10002], result[2];
assert(fgets(linha, 10000, stdin) != NULL);
n = atoi(linha);

inicializa3(&Campeonatos, n);

/* le linha em branco */
assert(fgets(linha, 10000, stdin) != NULL);
while(n>0)
{

(&Campeonatos)->caso[n-1] = n;

assert(fgets(linha, 10000, stdin) != NULL);
{
/*GUARDA OS DADOS DE UMA LINHA EM ALGUM LUGAR
Eles estao disponiveis em a, b, c, s[0]
*/

if (!(&DesafioAux)->acertou[numDesafio-1])
{
if (result[0] == 'C')
{

//incrementa com a penalidade das incorretas
(&DesafioAux)->acertou[numDesafio-1] = true;
}
else if (result[0] == 'I')
{
}
}

/* le a proxima linha */
if(fgets(linha, 10000, stdin) == NULL) break;
}

DEBUG(printf("fim do contest\n");)
n--;

}

for (index=(&Campeonatos)->tam - 1; index >=0; index--)
{

if (index < (&Campeonatos)->tam - 1)
printf("\n\n");

int indexAux;
for (indexAux=0; indexAux < (&Jogadores)->n; indexAux++)
{

if(indexAux > 0)
printf("\n");

printf("%d %d %d ",

}

}

DEBUG(printf("fim\n");)
return 0;

}

void Ordena(vetor *s){

int aInserir[3];

int i;
for (i=1; i<s->n; i++)
{

aInserir[1] = s->qtdeAcertos[i];

int j=i;
while((j > 0) && (
s->qtdeAcertos[j-1] < aInserir[1] ||
(s->qtdeAcertos[j-1] == aInserir[1] && s->totPenalidades[j-1] > aInserir[2]) ||
(s->qtdeAcertos[j-1] == aInserir[1] && s->totPenalidades[j-1] == aInserir[2] && s->numJogador[j-1] > aInserir[0]) ||
(s->qtdeAcertos[j-1] == 0 && s->numJogador[j-1] > aInserir[0])
))
{
s->qtdeAcertos[j] = s->qtdeAcertos[j-1];

j--;

}
s->qtdeAcertos[j] = aInserir[1];

}

}

{

int index;
for (index=0; index < s->n; index++)
{
return index;
}

return index;

}

/* inicializacao de uma estrutura vetor. Recebe um
ponteiro s para a estrutura a ser inicializada e
o tamanho t>0 desejado para o array. */
void inicializa(vetor *s, int t) {
/* comeca o n com zero, indicando que nada esta
armazenado em s->v por enquanto */
s->n = 0;
s->tam = t;
s->qtdeAcertos = malloc(sizeof(int)*t);
s->desafios = malloc(sizeof(vetor2)*t);

int index;
for (index=0; index <= t-1; index++)
{
inicializa2(&(s->desafios[index]), 10);
}
}

void inicializa2(vetor2 *s, int t) {
/* comeca o n com zero, indicando que nada esta
armazenado em s->v por enquanto */
s->n = 0;
s->tam = t;
s->numDesafio = malloc(sizeof(int)*t);
s->acertou = malloc(sizeof(int)*t);

int index;
for (index=1; index <= t; index++)
{
s->numDesafio[index-1] = index;
s->acertou[index-1] = false;
}

}

void inicializa3(vetor3 *s, int t) {
/* comeca o n com zero, indicando que nada esta
armazenado em s->v por enquanto */
s->n = 0;
s->tam = t;
s->caso = malloc(sizeof(int)*t);

int index;
for (index=0; index <= t-1; index++)
{
}

}

/* insercao de elemento na estrutura vetor. Recebe um
ponteiro s para a estrutura, a posicao pos para ser
inserido o elemento e o valor elem do elemento */
void insere(vetor *s, int numJogador) {
int i;

/* se tamanho ja eh s->tam, entao nao temos mais espaco para
inserir novos elementos */
if(tamanho(s)>=s->tam)
perror("Vetor cheio");

/* coloca o elem no array v */
s->qtdeAcertos[s->n] = 0;

s->n++;
}

/* devolve quantos elementos estao armazenados na estrutura s */
int tamanho(vetor *s) {
/* simplesmente retorna o n da estrutura */
return s->n;
}
``````
Thanks!!
Last edited by carpaneses on Sat Jul 07, 2007 4:09 pm, edited 1 time in total.

mmonish
Experienced poster
Posts: 109
Joined: Sun Mar 11, 2007 2:55 pm
Location: SUST
Presentation Error means output format error. newline or spaces can cause PE.
Read the output specification & hope u will find the coz of getting PE.

carpaneses
New poster
Posts: 3
Joined: Sat Jun 30, 2007 5:52 pm
Location: Sao Paulo - Brasil
Im still getting PE.

And I read repeatly times the output specification. Look for samples in this post. And I dont know why I stiil getting PE.

Please some one cal help me? My code is in the last post of previous page.

Thanks a lot!

mmonish
Experienced poster
Posts: 109
Joined: Sun Mar 11, 2007 2:55 pm
Location: SUST
Here u print one extra space. I think this will be the coz of getting PE.

Code: Select all

``````printf("%d %d %d ",
``The outputs of two consecutive cases will be separated by a blank line.``