結果
| 問題 |
No.241 出席番号(1)
|
| ユーザー |
norioc
|
| 提出日時 | 2018-08-25 12:20:37 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,675 bytes |
| コンパイル時間 | 426 ms |
| コンパイル使用メモリ | 11,520 KB |
| 最終ジャッジ日時 | 2024-11-14 20:35:52 |
| 合計ジャッジ時間 | 1,307 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
Main.d(1): Error: unable to read module `all` Main.d(1): Expected 'std/experimental/all.d' or 'std/experimental/all/package.d' in one of the following import paths: import path[0] = /opt/dmd/src/druntime/import/ import path[1] = /opt/dmd/src/phobos import path[2] = /home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd
ソースコード
import std.experimental.all;
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
alias MatchResult = Tuple!(int, "count", int[], "left", int[], "right");
MatchResult maxBipartiteMatching(bool[][] g) {
bool rec(int p, int[] left, int[] right, bool[][] g, bool[] used) {
for (int i = 0; i < right.length; i++) {
if (g[p][i] && right[i] == -1) {
left[p] = i;
right[i] = p;
return true;
}
}
for (int i = 0; i < right.length; i++) {
if (g[p][i] && !used[i]) {
used[i] = true;
if (rec(right[i], left, right, g, used)) {
left[p] = i;
right[i] = p;
return true;
}
}
}
return false;
}
auto left = new int[g.length];
auto right = new int[g[0].length];
left[] = -1;
right[] = -1;
int cnt = 0;
for (int i = 0; i < left.length; i++) {
auto used = new bool[left.length];
if (rec(i, left, right, g, used)) {
cnt++;
}
}
return MatchResult(cnt, left, right);
}
void main() {
int n = readint;
int[] a;
for (int i = 0; i < n; i++) {
a ~= readint;
}
auto g = new bool[][](n, n);
for (int i = 0; i < n; i++) {
g[i][] = true;
g[i][a[i]] = false;
}
auto result = maxBipartiteMatching(g);
if (result.count == result.left.length) {
foreach (x; result.left)
writeln(x);
}
else writeln(-1);
}
norioc