結果
| 問題 | No.679 不思議マーケット | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-04-27 23:23:13 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 156 ms / 2,000 ms | 
| コード長 | 1,761 bytes | 
| コンパイル時間 | 924 ms | 
| コンパイル使用メモリ | 107,404 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-13 00:56:25 | 
| 合計ジャッジ時間 | 2,336 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 18 | 
ソースコード
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math, std.typecons;
void main() {
    int n, m;
    scan(n, m);
    int[int] map;
    auto adj = new int[][](m, 0);
    foreach (i ; 0 .. m) {
        int gi, ri; scan(gi, ri);
        map[gi] = i;
        adj[i] = readln.split.to!(int[]);
    }
    auto mat = new int[][](m, m);
    foreach (i ; 0 .. m) {
        foreach (j ; adj[i]) {
            if (j !in map) continue;
            mat[map[j]][i] = 1;
        }
    }
    debug {
        writefln("%(%(%s %)\n%)", mat);
    }
    auto ans = n - m;
    auto vis = new bool[](m);
    while (true) {
        if (ans == n) break;
        int k = -1;
        foreach (j ; 0 .. m) {
            auto b = iota(m).all!(i => !mat[i][j]);
            if (b && !vis[j]) {
                k = j;
                break;
            }
        }
        if (k == -1) {
            break;
        }
        debug {
            writeln("k:", k);
        }
        vis[k] = true;
        ans++;
        foreach (j ; 0 .. m) {
            mat[k][j] = 0;
        }
        debug {
            writefln("%(%(%s %)\n%)", mat);
            writeln;
        }
    }
    writeln(ans);
}
void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;
    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
            
            
            
        