結果

問題 No.241 出席番号(1)
ユーザー bal4ubal4u
提出日時 2019-04-14 16:28:28
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,431 bytes
コンパイル時間 507 ms
コンパイル使用メモリ 30,656 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 06:37:05
合計ジャッジ時間 2,322 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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:29:17: note: in expansion of macro 'pc'
   29 |         if (!n) pc('0');
      |                 ^~

ソースコード

diff #

// yukicoder: No.241 出席番号(1)
// 2019.4.14 bal4u
// 最大2部マッチング

#include <stdio.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();
	//	while (isspace(c)) c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '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]);
	}
	pc('\n');
}

//// 最大2部マッチング
#define MAX 105
int  hi[MAX], to[MAX][MAX];
char seen[MAX];
int  match[MAX];

int bpm(int u)
{
	int i, v;

	for (i = 0; i < hi[u]; i++) {
		v = to[u][i];
		if (seen[v]) continue;
		seen[v] = 1;
		if (match[v] < 0 || bpm(match[v])) {
			match[u] = v, match[v] = u;
			return 1;
		}
	}
	return 0;
}

int bipartiteMatching(int m, int n)
{
	int u, max;

	memset(match, -1, (m + n) * sizeof(int));
	max = 0;
	for (u = 0; u < m; u++) {
		memset(seen, 0, m + n);
		if (bpm(u)) max++;
	}
	return max;
}

int main()
{
	int i, j, a, N;

	N = in();
	for (i = 0; i < N; i++) {
		a = in();
		for (j = 0; j < N; j++) if (j != a) to[i][hi[i]++] = N + j;
	}
	if (bipartiteMatching(N, N) != N) { puts("-1"); return 0; }
	for (i = 0; i < N; i++) out(match[i] - N);
	return 0;
}
0