結果

問題 No.628 Tagの勢い
ユーザー bal4ubal4u
提出日時 2019-05-01 09:28:46
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,875 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 30,304 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 04:15:46
合計ジャッジ時間 1,637 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 0 ms
4,376 KB
testcase_04 AC 0 ms
4,376 KB
testcase_05 AC 0 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 0 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:10:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   10 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:18:24: 備考: in expansion of macro ‘gc’
   18 |         int n = 0, c = gc();
      |                        ^~
main.c: 関数 ‘out’ 内:
main.c:11:15: 警告: 関数 ‘putchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   11 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:36:17: 備考: in expansion of macro ‘pc’
   36 |         if (!n) pc('0');
      |                 ^~

ソースコード

diff #

// yukicoder: No.628 Tagの勢い
// 2019.5.1 bal4u

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

// 高速入力
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()    // 非負整数の入力
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void ins(char *s)  // 文字列の入力 スペース以下の文字で入力終了
{
	char *p = s;
	do *s = gc();
	while (*s++ > ' ');
	*--s = 0;
}

void out(int n)  // 非負整数の表示(出力)
{
	int i;
	char b[20];

	if (!n) pc('0');
	else {
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

void outs(char *s) { while (*s) pc(*s++); }


// 文字列のハッシュ関数
#define HASHSIZ  49999
typedef struct { char *s; int id; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash + HASHSIZ;

int insert(char *s, int id)
{
	unsigned long long i;
	int j;
	char *p;
	HASH *tp;

	i = 0, p = s;
	for (j = 0; *p && j < 12; j++) i = (i << 5) + (*p++ +1-'a');
	tp = hash + (int)(i % HASHSIZ);
	while (tp->s != NULL) {
		if (!strcmp(tp->s, s)) return tp->id;
		if (++tp == hashend) tp = hash;
	}
	tp->s = s, tp->id = id;
	return -1;
}


// 本問題関連
typedef struct { char *s; int u; } T;
T t[10003];
char tag[10003][22]; int sz;

int cmp(const void *a, const void *b)
{
	int t;
	if (t = ((T *)b)->u - ((T *)a)->u) return t;
	return strcmp(((T *)a)->s, ((T *)b)->s);
}

int main()
{
	int k, N, M, S;
	
	N = in();
	while (N--) {
		in(), M = in(), S = in();
		while (M--) {
			ins(tag[sz]);
			k = insert(tag[sz], sz);
			if (k < 0) t[sz].s = tag[sz], t[sz].u = S, sz++;
			else t[k].u += S;
		}
	}
	qsort(t, sz, sizeof(T), cmp);
	if (sz > 10) sz = 10;
	for (k = 0; k < sz; k++) {
		outs(t[k].s), pc(' '), out(t[k].u);
	}
	return 0;
}
		
0