結果

問題 No.2153 何コーダーが何人?
ユーザー pengin_2000pengin_2000
提出日時 2022-12-09 21:59:29
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,610 bytes
コンパイル時間 512 ms
コンパイル使用メモリ 32,512 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-22 22:07:11
合計ジャッジ時間 1,401 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<stdio.h>
int strcmp(char s[], char t[])
{
	int i = 0;
	for (;; i++)
	{
		if (s[i] == '\0' && t[i] == '\0')
			return 0;
		if (t[i] == '\0')
			return 1;
		if (s[i] == '\0')
			return -1;
		if (s[i] > t[i])
			return 1;
		if (s[i] < t[i])
			return -1;
	}
}
int h[2003], l;
char s[2003][202];
int comp_h(int a, int b)
{
	int r= strcmp(s[h[a]], s[h[b]]);
	if (r == 0)
	{
		if (h[a] < h[b])
			r = 1;
		else
			r = -1;
	}
	return r;
}
void swap_h(int a, int b)
{
	int f = h[a];
	h[a] = h[b];
	h[b] = f;
	return;
}
void push(int ne)
{
	h[l] = ne;
	int p = l;
	l++;
	for (; p > 0; p = (p - 1) / 2)
		if (comp_h((p - 1) / 2, p) > 0)
			swap_h((p - 1) / 2, p);
	return;
}
int pop()
{
	l--;
	swap_h(0, l);
	int p = 0;
	for (;;)
	{
		if (2 * p + 2 < l)
		{
			if (comp_h(2 * p + 1, 2 * p + 2) > 0)
			{
				if (comp_h(p, 2 * p + 2) > 0)
					swap_h(p, 2 * p + 2);
				p = 2 * p + 2;
			}
			else
			{
				if (comp_h(p, 2 * p + 1) > 0)
					swap_h(p, 2 * p + 1);
				p = 2 * p + 1;
			}
		}
		else if (2 * p + 1 < l)
		{
			if (comp_h(p, 2 * p + 1) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return h[l];
}
int c[2003];
int sort_ind[2003];
int ans[11];
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	for (i = 0; i < n; i++)
		scanf("%s %d", s[i], &c[i]);
	l = 0;
	for (i = 0; i < n; i++)
		push(i);
	for (i = 0; i < n; i++)
		sort_ind[i] = pop();
	for (i = 0; i < 8; i++)
		ans[i] = 0;
	ans[c[sort_ind[0]]]++;
	for (i = 1; i < n; i++)
		if (strcmp(s[sort_ind[i]], s[sort_ind[i - 1]]) != 0)
			ans[c[sort_ind[i]]]++;
	for (i = 0; i < 8; i++)
		printf("%d\n", ans[i]);
	return 0;
}
0