結果

問題 No.447 ゆきこーだーの雨と雪 (2)
ユーザー くれちー
提出日時 2016-11-19 19:18:30
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 3,372 bytes
コンパイル時間 378 ms
コンパイル使用メモリ 23,424 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-27 06:08:45
合計ジャッジ時間 2,361 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:95:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   95 |         scanf("%d", &n);
      |         ^~~~~~~~~~~~~~~
main.c:101:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  101 |                 scanf("%d", &l);
      |                 ^~~~~~~~~~~~~~~
main.c:106:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  106 |         scanf("%d", &t);
      |         ^~~~~~~~~~~~~~~
main.c:113:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  113 |                 scanf("%s %c", name[i], &p[i]);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct {
	int Level;
	int Solve;
} Problem;

Problem *Problem_New(int level) {
	Problem *p;
	p = (Problem *)malloc(sizeof(Problem));
	p->Level = level;
	p->Solve = 0;
	return p;
}

int Problem_GetId(char name) {
	return name - 'A';
}

typedef struct {
	char *Name;
	char ProblemName;
} Submit;

Submit *Submit_New(char *name, char problemName) {
	Submit *s;
	s = (Submit *)malloc(sizeof(Submit));
	s->Name = name;
	s->ProblemName = problemName;
	return s;
}

typedef struct {
	char *Name;
	int Score[26];
	int ScoreSum;
	int LastSubmit;
} Participant;

Participant *Participant_New_1(char *name) {
	Participant *p;
	p = (Participant *)malloc(sizeof(Participant));
	p->Name = name;
	return p;
}

Participant *Participant_New_2(char *name, int problemNum, int lastSubmit) {
	Participant *p;
	p = (Participant *)malloc(sizeof(Participant));
	p->Name = name;
	int i;
	for (i = 0; i < problemNum; i++) p->Score[i] = 0;
	p->ScoreSum = 0;
	p->LastSubmit = lastSubmit;
	return p;
}

int Participant_Equals(Participant *p1, Participant *p2) {
	return strcmp(p1->Name, p2->Name) == 0 ? 1 : 0;
}

int Participant_CompareTo(const void *p1, const void *p2) {
	if (((Participant *)p1)->ScoreSum == ((Participant *)p2)->ScoreSum)
		return ((Participant *)p1)->LastSubmit - ((Participant *)p2)->LastSubmit;
	else
		return ((Participant *)p2)->ScoreSum - ((Participant *)p1)->ScoreSum;
}

void Participant_Solve(Participant *p, int no, int level, int rank) {
	p->Score[no] = 50 * level + (500 * level / (8 + 2 * rank));
	p->ScoreSum += p->Score[no];
}

int Participant_List_Contains(Participant *p1, int size, Participant *p2) {
	int i;
	for (i = 0; i < size; i++) {
		if (Participant_Equals(&p1[i], p2)) return 1;
	}
	return 0;
}

int Participant_List_IndexOf(Participant *p1, int size, Participant *p2) {
	int i;
	for (i = 0; i < size; i++) {
		if (Participant_Equals(&p1[i], p2)) return i;
	}
	return -1;
}


int main() {
	int n;
	scanf("%d", &n);
	Problem problemList[26];

	int i, j;
	for (i = 0; i < n; i++) {
		int l;
		scanf("%d", &l);
		problemList[i] = *Problem_New(l);
	}
	
	int t;
	scanf("%d", &t);
	Submit submitList[4000];
	int cntParticipant = 0;
	Participant participantList[4000];

	for (i = 0; i < t; i++) {
		char name[4000][17], p[4000];
		scanf("%s %c", name[i], &p[i]);
		submitList[i] = *Submit_New(name[i], p[i]);

		if (!Participant_List_Contains(participantList, cntParticipant, 
			Participant_New_1(submitList[i].Name))) {
			participantList[cntParticipant] = *Participant_New_2(name[i], n, i);
			cntParticipant++;
		}

		int tmpProblemNo = 
			Problem_GetId(submitList[i].ProblemName);
		int tmpParticipantNo = 
			Participant_List_IndexOf(participantList, cntParticipant, 
				Participant_New_1(submitList[i].Name));

		problemList[tmpProblemNo].Solve++;
		Participant_Solve(
			&participantList[tmpParticipantNo], 
			tmpProblemNo, 
			problemList[tmpProblemNo].Level, 
			problemList[tmpProblemNo].Solve
		);
		participantList[tmpParticipantNo].LastSubmit = i;
	}

	qsort(participantList, cntParticipant, 
		sizeof(Participant), Participant_CompareTo);

	for (i = 0; i < cntParticipant; i++) {
		printf("%d %s ", i + 1, participantList[i].Name);
		for (j = 0; j < n; j++) {
			printf("%d ", participantList[i].Score[j]);
		}
		printf("%d\n", participantList[i].ScoreSum);
	}

	return 0;
}
0