結果
| 問題 | 
                            No.697 池の数はいくつか
                             | 
                    
| ユーザー | 
                             norioc
                         | 
                    
| 提出日時 | 2018-08-30 23:41:04 | 
| 言語 | D  (dmd 2.109.1)  | 
                    
| 結果 | 
                             
                                CE
                                 
                             
                            
                            (最新)
                                AC
                                 
                             
                            (最初)
                            
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,591 bytes | 
| コンパイル時間 | 47 ms | 
| コンパイル使用メモリ | 11,264 KB | 
| 最終ジャッジ日時 | 2024-11-15 04:47:20 | 
| 合計ジャッジ時間 | 1,323 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge1 | 
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、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;
// 3.3 sec で AC
int calc(int[][] g) {
    int rows = cast(int)g.length;
    int cols = cast(int)g[0].length;
    auto delta = [[-1, 0], [1, 0], [0, -1], [0, 1]];
    void fill(int row, int col, int[][] g, int[][] used) {
        assert(g[row][col] == 1);
        auto q = DList!(int)();
        // [row, col] で配列生成すると TLE (2 sec 近く遅くなる)
        q.insertBack((row << 16) | col);
        while (!q.empty) {
            auto a = q.front;
            q.removeFront();
            int r = (a >> 16), c = a & 0xffff;
            if (used[r][c]++) continue;
            foreach (d; delta) {
                int r2 = r + d[0];
                int c2 = c + d[1];
                if (!(0 <= r2 && r2 < rows && 0 <= c2 && c2 < cols)) continue;
                if (g[r2][c2] == 0 || used[r2][c2]) continue;
                q.insertBack((r2 << 16) | c2);
            }
        }
    }
    int ans = 0;
    auto used = new int[][](rows, cols);
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            if (used[i][j]) continue;
            if (g[i][j] == 1) {
                ans++;
                fill(i, j, g, used);
            }
        }
    }
    return ans;
}
void main() {
    auto hw = readints;
    int h = hw[0], w = hw[1];
    auto g = new int[][](h, w);
    for (int i = 0; i < h; i++) {
        g[i][] = readints;
    }
    writeln(calc(g));
}
            
            
            
        
            
norioc