結果

問題 No.628 Tagの勢い
ユーザー Mcpu3Mcpu3
提出日時 2018-10-23 21:56:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,049 bytes
コンパイル時間 651 ms
コンパイル使用メモリ 66,928 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 20:19:01
合計ジャッジ時間 3,465 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 2 ms
5,376 KB
testcase_03 RE -
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 2 ms
5,376 KB
testcase_18 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
using namespace std;

struct s {
	int score;
	string word;
};

int compare(const void *x, const void *y)
{
	return ((s*)y)->score - ((s*)x)->score;
}

void insertionSort(int *top, s tag[])
{
	int j;
	s tmp;
	for (int i = 1; i < *top; ++i) {
		tmp = tag[i];
		for (j = i - 1; j >= 0 && tag[j].word > tmp.word && tag[j].score == tmp.score; --j) tag[j + 1] = tag[j];
		tag[j + 1] = tmp;
	}

}

int main() {
	int N, M, S, top = 0, k;
	string tmp;
	s tag[10000];
	cin >> N;
	for (int i = 0; i < N; ++i) {
		scanf("%*d%d%d", &M, &S);
		for (int j = 0; j < M; ++j) {
			cin >> tmp;
			for (k = 0; k < top; ++k) {
				if (tag[k].word == tmp) break;
			}
			if (k == top) {
				tag[top].word = tmp;
				tag[top].score = S;
				++top;
			}
			else tag[k].score += S;
		}
	}
	qsort(tag, top, sizeof(s), compare);
	insertionSort(&top, tag);
	for (int i = 0; i < 10 && i < top; ++i) cout << tag[i].word << " " << tag[i].score << endl;
}
0