結果
| 問題 |
No.628 Tagの勢い
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-05-01 09:28:46 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,875 bytes |
| コンパイル時間 | 332 ms |
| コンパイル使用メモリ | 31,488 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-31 12:10:32 |
| 合計ジャッジ時間 | 1,256 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
main.c: In function 'in':
main.c:10:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
10 | #define gc() getchar_unlocked()
| ^~~~~~~~~~~~~~~~
main.c:18:24: note: in expansion of macro 'gc'
18 | int n = 0, c = gc();
| ^~
main.c: In function 'out':
main.c:11:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
11 | #define pc(c) putchar_unlocked(c)
| ^~~~~~~~~~~~~~~~
main.c:36:17: note: in expansion of macro 'pc'
36 | if (!n) pc('0');
| ^~
ソースコード
// 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;
}
bal4u