結果
| 問題 |
No.241 出席番号(1)
|
| ユーザー |
bal4u
|
| 提出日時 | 2019-04-14 16:28:28 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 1,431 bytes |
| コンパイル時間 | 493 ms |
| コンパイル使用メモリ | 30,464 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-19 02:57:39 |
| 合計ジャッジ時間 | 1,847 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
コンパイルメッセージ
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');
| ^~
ソースコード
// 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;
}
bal4u