結果

問題 No.812 Change of Class
ユーザー bal4ubal4u
提出日時 2019-07-13 18:43:59
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 104 ms / 4,000 ms
コード長 1,812 bytes
コンパイル時間 1,051 ms
コンパイル使用メモリ 31,044 KB
実行使用メモリ 7,788 KB
最終ジャッジ日時 2023-09-03 15:34:48
合計ジャッジ時間 5,978 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
6,372 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 13 ms
4,380 KB
testcase_03 AC 30 ms
7,320 KB
testcase_04 AC 27 ms
6,540 KB
testcase_05 AC 104 ms
6,632 KB
testcase_06 AC 103 ms
7,788 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 0 ms
4,384 KB
testcase_09 AC 83 ms
7,168 KB
testcase_10 AC 86 ms
7,184 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 45 ms
6,624 KB
testcase_13 AC 0 ms
4,376 KB
testcase_14 AC 0 ms
4,376 KB
testcase_15 AC 61 ms
5,124 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 52 ms
5,528 KB
testcase_18 AC 41 ms
4,452 KB
testcase_19 AC 46 ms
4,824 KB
testcase_20 AC 87 ms
7,072 KB
testcase_21 AC 40 ms
4,380 KB
testcase_22 AC 17 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 5 ms
4,380 KB
testcase_25 AC 13 ms
4,380 KB
testcase_26 AC 72 ms
6,164 KB
testcase_27 AC 68 ms
5,644 KB
testcase_28 AC 45 ms
4,892 KB
testcase_29 AC 11 ms
4,380 KB
testcase_30 AC 60 ms
5,308 KB
testcase_31 AC 50 ms
4,796 KB
testcase_32 AC 22 ms
4,384 KB
testcase_33 AC 63 ms
5,860 KB
testcase_34 AC 5 ms
4,380 KB
testcase_35 AC 10 ms
4,380 KB
testcase_36 AC 4 ms
4,388 KB
testcase_37 AC 26 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 26 ms
4,380 KB
testcase_40 AC 7 ms
4,380 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 56 ms
5,476 KB
testcase_43 AC 7 ms
4,384 KB
testcase_44 AC 37 ms
4,392 KB
testcase_45 AC 4 ms
4,380 KB
testcase_46 AC 6 ms
4,380 KB
testcase_47 AC 35 ms
4,404 KB
testcase_48 AC 41 ms
4,904 KB
testcase_49 AC 10 ms
4,380 KB
testcase_50 AC 1 ms
4,380 KB
testcase_51 AC 10 ms
4,380 KB
testcase_52 AC 18 ms
4,388 KB
testcase_53 AC 7 ms
4,376 KB
testcase_54 AC 6 ms
4,376 KB
testcase_55 AC 17 ms
5,660 KB
testcase_56 AC 19 ms
6,496 KB
testcase_57 AC 21 ms
6,852 KB
testcase_58 AC 11 ms
4,376 KB
testcase_59 AC 23 ms
7,552 KB
testcase_60 AC 0 ms
4,376 KB
testcase_61 AC 1 ms
4,380 KB
testcase_62 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:9:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    9 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:17:24: 備考: in expansion of macro ‘gc’
   17 |         int n = 0, c = gc();
      |                        ^~
main.c: 関数 ‘out’ 内:
main.c:10:15: 警告: 関数 ‘putchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   10 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:26:17: 備考: in expansion of macro ‘pc’
   26 |         if (!n) pc('0');
      |                 ^~

ソースコード

diff #

// yukicoder: No.812 Change of Class
// 2019.7.13 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); while ((c = gc()) >= '0');
	return n;
}

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]);
	}
}

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

#define QMAX 10000000
#define MAX 100005
typedef struct { int a, s; } Q;
Q que[QMAX+3]; int top, end;
int N;
int *to[MAX], hi[MAX];
char vis[MAX];

int calc(int n) {
	int i = 0;
	while (n) i++, n >>= 1;
	return i;
}

int main()
{
	int i, a, p, q, s, M, Q, ma;
	int *memo, sz;
	
	N = in(), M = in();
	memo = malloc(sizeof(int)*M*2);
	sz = 0;	while (M--) {
		p = in()-1, q = in()-1;
		memo[sz++] = p, memo[sz++] = q;
		hi[p]++, hi[q]++;
	}
	i = N; while (i--) if (hi[i]) to[i] = malloc(sizeof(int)*hi[i]);
	memset(hi, 0, sizeof(int)*N);
	
	i = 0; while (i < sz) {
		p = memo[i++], q = memo[i++];
		to[p][hi[p]++] = q, to[q][hi[q]++] = p;
	}
//	free(memo);
	
	Q = in(); while (Q--) {
		a = in()-1;
		if (hi[a] == 0) { outs("0 0\n"); continue; }
		que[0].a = a, que[0].s = 0, top = 0, end = 1, sz = ma = 0;
		memset(vis, 0, N);
		while (top != end) {
			p = que[top].a, s = que[top].s;
			if (++top == QMAX) top = 0;
			if (s > ma) ma = s;
			if (vis[p]) continue;
			vis[p] = 1, sz++;
			for (i = 0; i < hi[p]; i++) {
				q = to[p][i];
				if (!vis[q]) {
					que[end].a = q, que[end].s = s+1;
					if (++end == QMAX) end = 0;
				}
			}
		}
		out(sz-1), pc(' '), out(calc(ma-1)), pc('\n');
	}
	return 0;
}
0